I do have some more complex projects where if you run pytest --collect-only you will endup with lots of import failures caused by discovered test files that have imports of stuff that were not installed yet.
I want to change these test files in such way that they would not fail on collection.
This is because the user may want to run tests using a specific pattern like pytest -k foo, but he would not be able to do this if collection fails on unrelated tests.
I know that I can define a pytest_configure method that would be called durind collection but if I move the imports into it I would still get failures later when the interpreter is reaching code trying to use the missing imports.
pytest.skip("skipping when foo is not installed")
assert foo.is_enabled() # <-- foo is undefined here
My example is clearly over similified as we all know that I could add the import again in the test method but I do not want to do this in tens of methods. I am looking for a cleaner solution.