Testing with global context-provided code #9330
-
My tests structure looks like this -
In the nested conftest I use the pytest_collectstart like this - def pytest_collectstart(collector):
os.environ['API_KEY'] = '...'
sys.modules['somelib'] = Mock() Without this the tests wouldn't run (the code there're importing would raise). I didn't find an opposite hook to pytest_collectstart to use for cleanup. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
I would strongly recommend a scoped fixture, hacks with sys. Modules make for fragile tests, and I typically strongly recommended against them |
Beta Was this translation helpful? Give feedback.
I would strongly recommend a scoped fixture, hacks with sys. Modules make for fragile tests, and I typically strongly recommended against them