|
I think it's common particularly when deploying services in containers to get some configuration from environment, at the top of a module, like this: In this use case it's usually too late to use My workaround for this is to rely on the fact that But it seems a bit off-label usage and I'm not sure if it's actually documented/guaranteed that putting this in I wonder if this is something that we could do in pytest config file directly? There's a plugin pytest-env which is small and simple and does similar: A concern though is that there's some danger of "production" config values being used if the tests were accidentally run without the plugin installed. Could a feature like this go into pytest directly? |
Replies: 3 comments 4 replies
|
Hi @wimglenn! Integrating |
|
The concern of interacting with default or externally configured services is mitigated by using the required_plugins setting mentioned in the comments. That makes the test session abort early if |
|
This discussion highlights an interesting testing problem beyond simply setting an environment variable: knowing whether the meaningful configuration states are actually exercised by the test suite. I’ve been exploring this from a static-analysis angle with an open-source tool called ConfigReach: https://github.com/sauravsingla/ConfigReach It inventories environment-variable reads such as os.getenv / os.environ, looks for corresponding test evidence such as monkeypatch.setenv, and reports configuration inputs or known values that appear untested. The import-time case discussed here is particularly interesting because static test evidence does not necessarily mean the configuration affected the intended execution path. I’m curious whether pytest users would find it useful to distinguish between: an environment variable being set somewhere in tests, and That distinction is one of the problems I’m trying to model deterministically. |
The concern of interacting with default or externally configured services is mitigated by using the required_plugins setting mentioned in the comments.
That makes the test session abort early if
pytest-envwasn't installed, rather than just print a warning about unrecognized config options.