❯ pytest test.py --doctest-modules
=========================================================== test session starts ============================================================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /tmp
collected 1 item
test.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/main.py", line 269, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/main.py", line 323, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/main.py", line 348, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/runner.py", line 109, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/runner.py", line 120, in runtestprotocol
INTERNALERROR> rep = call_and_report(item, "setup", log)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/runner.py", line 217, in call_and_report
INTERNALERROR> report: TestReport = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR> self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR> gen.send(outcome)
INTERNALERROR> File "/home/lesteve/miniconda3/envs/test/lib/python3.9/site-packages/_pytest/skipping.py", line 314, in pytest_runtest_makereport
INTERNALERROR> assert line is not None
INTERNALERROR> AssertionError
========================================================== no tests ran in 0.01s ===========================================================
This is a simplified issue from a real use case in the scikit-learn repo. We sometimes want to skip doctests, for example when matplotlib (an optional dependency) is not installed. If there is be a better way to do it with pytest than using pytest_collection_modifyitems, let me know.
To reproduce:
This is a simplified issue from a real use case in the scikit-learn repo. We sometimes want to skip doctests, for example when matplotlib (an optional dependency) is not installed. If there is be a better way to do it with pytest than using
pytest_collection_modifyitems, let me know.conda list output