Force a specific test to always run regardless of "-k"
See original GitHub issueHi,
I am trying to add a test to my pytest suite that will verify the python version that is used to run the test and fail and stop testing if the version is lower than 3.8. I’d like to get pytest to always run this test, regardless of any “-k” filtering done on the command line.
For reference, this is the actual test:
@pytest.mark.tryfirst
def test_python_version():
version = sys.version_info
if version.major < 3:
logging.error("python2 is not supported")
pytest.exit("Stopped testing")
elif version.minor < 8:
logging.warning("Use python 3.8 or higher for best results")
I’m a bit new to pytest, but I couldn’t find any marker that provides this functionality. Regardless of the specific aforementioned use case, it seems to me to be a pretty useful thing to have implemented, IMHO.
Asked this question in SO, with no responses: https://stackoverflow.com/questions/59094496/force-pytest-to-always-run-a-specific-test-regardless-of-k
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Force pytest to always run a specific test, regardless of "-k"
I am trying to add a test to my pytest suite that will verify the python version that is used to run the...
Read more >Effective Python Testing With Pytest
pytest-randomly forces your tests to run in a random order. pytest always collects all the tests it can find before running them. pytest- ......
Read more >API Reference — pytest documentation
run (bool) – If the test function should actually be executed. If False , the function will always xfail and will not be...
Read more >Running Tests | Create React App
Create React App uses Jest as its test runner. ... This means that the tests always run in a Node environment and not...
Read more >test - Pants build system
This also gives you fine-grained invalidation. If you run ./pants test :: , and then you only change one file, then only tests...
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
I see thanks.
I’m not sure about misguided, but I think it should be enough to have this failing the entire test session during
pytest_configure
, not the responsibility of a single test.Closing this issue because I think the question has been answered: the consensus is to use a hook or fixure rather than a test for such code.