importorskip decorator on one test skips entire module
See original GitHub issueBud Description
When using pytest.importorskip as a decorator on a specific test in a test file, the all of the the tests in the file, rather than just the decorated test, are skipped.
For example:
# contents of test_it,py
import pytest
@pytest.importorskip('a_module_that_isnt_installed')
def tests_one():
assert 1
def test_two():
assert 0
when running:
pytest test_it.py -rsx
I get the following output:
============================= test session starts ==============================
platform linux -- Python 3.10.2, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/derrick/python_scratch_space/importorskip
collected 0 items / 1 skipped
=========================== short test summary info ============================
SKIPPED [1] test_it.py:3: could not import 'a_module_that_isnt_installed': No module named 'a_module_that_isnt_installed'
============================== 1 skipped in 0.00s ==============================
However, I would expect test_two to still be collected and run.
Version Info
Package Version
---------- -------
attrs 21.4.0
iniconfig 1.1.1
packaging 21.3
pip 21.3.1
pluggy 1.0.0
py 1.11.0
pyparsing 3.0.7
pytest 6.2.5
setuptools 60.5.0
toml 0.10.2
wheel 0.37.1
pytest 6.2.5, python 10.2 ubuntu 20.04
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Pytest.importorskip test skipping
Skipping module imports is demonstrated in this example. Suppose “test_plots.py” has every function requiring Matplotlib. The whole file may be ...
Read more >How to use skip and xfail to deal with tests that cannot succeed
You can skip tests on a missing import by using pytest.importorskip at module level, within a test, or test setup function.
Read more >PyTest: skip entire module/file (python 2 and 3) - Stack Overflow
skip outside of a test is not allowed. If you are trying to decorate a test function, use the @pytest.mark.skip or @pytest.mark.skipif decorators...
Read more >pytest.importorskip - pytest Quick Start Guide [Book] - O'Reilly
pytest.importorskip will import the module and return the module object, or skip the test entirely if the module could not be .
Read more >Testing — Translate Toolkit 3.7.4 documentation
You can apply this decorator to classes as well as functions and methods. It is also possible to skip an entire test module...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

personally i’d prefer just deprecating a easy to misuse api instead of hacking it up with magic to somehow hopefully be able to error
Not sure, perhaps it would bring more confusion than help out? We see users confusing
pytest.mark.skipandpytest.skipalready… 🤔