File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change 88
99_ORIG_ENVIRON = None
1010
11+ _modmail_env_prefix = "MODMAIL_"
12+
1113
1214def pytest_report_header (config ) -> str :
1315 """Pytest headers."""
@@ -26,17 +28,35 @@ def _get_env():
2628 return pathlib .Path (__file__ ).parent / "test.env"
2729
2830
31+ def _get_env_vars () -> dict :
32+ result = {}
33+ for key , value in os .environ .items ():
34+ # not using upper() since the config system is case sensitive
35+ if key .startswith (_modmail_env_prefix ):
36+ result [key ] = value
37+ return result
38+
39+
2940def pytest_configure ():
3041 """Load the test specific environment file, exit if it does not exist."""
42+ global _ORIG_ENVIRON
3143 env = _get_env ()
3244 if not env .is_file ():
3345 pytest .exit (f"Testing specific { env } does not exist. Cancelling test run." , 2 )
34- os .environ .clear ()
46+ _ORIG_ENVIRON = _get_env_vars ()
47+ for key in _ORIG_ENVIRON :
48+ del os .environ [key ]
49+
3550 dotenv .load_dotenv (_get_env (), override = True )
3651
3752
3853def pytest_unconfigure ():
3954 """Reset os.environ to the original environment before the run."""
40- if _ORIG_ENVIRON is not None :
41- os .environ .clear ()
42- os .environ .update (** _ORIG_ENVIRON )
55+ global _ORIG_ENVIRON
56+ if _ORIG_ENVIRON is None :
57+ return
58+
59+ for key in _get_env_vars ():
60+ del os .environ [key ]
61+ os .environ .update (** _ORIG_ENVIRON )
62+ _ORIG_ENVIRON = None
You can’t perform that action at this time.
0 commit comments