question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force a specific test to always run regardless of "-k"

See original GitHub issue

Hi,

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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nicoddemuscommented, Dec 5, 2019

I see thanks.

Feel free to correct me if I am maybe misguided here

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.

0reactions
Zac-HDcommented, Dec 8, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found