rudineirk / pytest-mocha

Pytest output in MochaJS format
MIT License
14 stars 4 forks source link

Error after testing completes #5

Open SeanOfTheHillPeople opened 3 months ago

SeanOfTheHillPeople commented 3 months ago

I'm getting the following error after my tests run, after the last test result is displayed and before the footer with counts and timing:

INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/main.py", line 322, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 152, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_result.py", line 114, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/main.py", line 347, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 152, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_result.py", line 114, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/runner.py", line 111, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/runner.py", line 130, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/_pytest/runner.py", line 223, in call_and_report
INTERNALERROR>     hook.pytest_runtest_logreport(report=report)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 113, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pytest_mocha/reporter.py", line 41, in report_replacer
INTERNALERROR>     file_name, text = load_test_info(report.nodeid)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pytest_mocha/loader.py", line 112, in load_test_info
INTERNALERROR>     class_text = load_class(module_name, class_name)
INTERNALERROR>   File "/Users/***/venv/lib/python3.10/site-packages/pytest_mocha/loader.py", line 43, in load_class
INTERNALERROR>     'class': module_class
INTERNALERROR> UnboundLocalError: local variable 'module_class' referenced before assignment
SeanOfTheHillPeople commented 3 months ago

It looks like this is caused by a parameterized test with triple-colon (:::) in one of the parameter values that becomes part of the test name:

@pytest.mark.parametrize(
    'percentage, combined_string',
    [(100, 'string1'), (10, 'string1:::string2')],
)

… which generates the test name:

test_foo_bar[10-string1:::string2]
SeanOfTheHillPeople commented 3 months ago

Created a PR to fix this.