KeyError _is_coroutine on hub.OPT
Given the code:
def _assert_block(hub, test_name: str, test_block: Dict) -> Dict:
assertion_section_delimiter = test_block.get(
"assertion_section_delimiter", hub.OPT["validator"]["delimiter"]
)
and associated test with mock_hub:
def test_assert_block(mock_hub):
test_name = 'a test'
test_dict = {"assertion": "assertEqual", "expected_return": "stuff", "assertion_section_delimiter": ":"}
check._assert_block(mock_hub, test_name, test_dict)
Returns the error
mock_hub = <root..local.share.virtualenvs.mypop-mGqZu586.lib.python3.7.site-packages.pop.mods.pop.testing.MockHub object at 0x7f9937892978>
def test_assert_block(mock_hub):
#mock_hub = hub.pop.testing.mock_hub()
test_name = 'a test'
test_dict = {"assertion": "assertEqual", "expected_return": "stuff", "assertion_section_delimiter": ":"}
> check._assert_block(mock_hub, test_name, test_dict)
tests/unit/test_check.py:51:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
validator/validator/check.py:39: in _assert_block
"assertion_section_delimiter", hub.OPT["validator"]["delimiter"]
/root/.local/share/virtualenvs/mypop-mGqZu586/lib/python3.7/site-packages/pop/mods/pop/testing.py:199: in __getattribute__
attr = self._orig_to_attr(orig)
/root/.local/share/virtualenvs/mypop-mGqZu586/lib/python3.7/site-packages/pop/mods/pop/testing.py:214: in _orig_to_attr
attr = self._mock_attr(orig)
/root/.local/share/virtualenvs/mypop-mGqZu586/lib/python3.7/site-packages/pop/mods/pop/testing.py:218: in _mock_attr
return create_autospec(a, spec_set=True)
/root/.local/share/virtualenvs/mypop-mGqZu586/lib/python3.7/site-packages/asynctest/mock.py:767: in create_autospec
is_coroutine_func = asyncio.iscoroutinefunction(spec)
/usr/lib/python3.7/asyncio/coroutines.py:163: in iscoroutinefunction
getattr(func, '_is_coroutine', None) is _is_coroutine)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = {'validator': {'version': False, 'log_file': 'validator.log', 'log_level': 'info', 'log_fmt_logfile': '%(asctime)s,%(m...n': 'basic', 'tests': ('testfile.tst',), 'render': 'jinja|yaml', 'delimiter': ':', 'workers': '5', 'output': 'nested'}}
k = '_is_coroutine'
def __getattr__(self, k: str):
> return self.__store[k]
E KeyError: '_is_coroutine'
/root/.local/share/virtualenvs/mypop-mGqZu586/lib/python3.7/site-packages/pop/mods/pop/data.py:55: KeyError
If in the function being tested, I replace
assertion_section_delimiter = test_block.get(
"assertion_section_delimiter", hub.OPT["validator"]["delimiter"]
)
with
assertion_section_delimiter = test_block.get(
"assertion_section_delimiter", ":"
)
I don't get the KeyError. So my issue seems to be in the parsing of the mocked hub.OPT (which you can see in the test error output, does contain the expected delimiter key.
What is the appropriate way to mock hub.OPT or otherwise get past the _is_coroutine
KeyError?
Edited by Christian McHugh