11
11
from _pytest .main import EXIT_NOTESTSCOLLECTED
12
12
from _pytest .main import EXIT_OK
13
13
from _pytest .main import EXIT_USAGEERROR
14
-
15
-
16
- @pytest .fixture (scope = "module" , params = ["global" , "inpackage" ])
17
- def basedir (request , tmpdir_factory ):
18
- tmpdir = tmpdir_factory .mktemp ("basedir" , numbered = True )
19
- tmpdir .ensure ("adir/conftest.py" ).write ("a=1 ; Directory = 3" )
20
- tmpdir .ensure ("adir/b/conftest.py" ).write ("b=2 ; a = 1.5" )
21
- if request .param == "inpackage" :
22
- tmpdir .ensure ("adir/__init__.py" )
23
- tmpdir .ensure ("adir/b/__init__.py" )
24
- return tmpdir
14
+ from _pytest .pytester import SysModulesSnapshot
15
+ from _pytest .pytester import SysPathsSnapshot
25
16
26
17
27
18
def ConftestWithSetinitial (path ):
@@ -42,6 +33,26 @@ def __init__(self):
42
33
43
34
44
35
class TestConftestValueAccessGlobal (object ):
36
+ @pytest .fixture (scope = "module" , params = ["global" , "inpackage" ])
37
+ def basedir (self , request , tmpdir_factory ):
38
+ tmpdir = tmpdir_factory .mktemp ("basedir" , numbered = True )
39
+ tmpdir .ensure ("adir/conftest.py" ).write ("a=1 ; Directory = 3" )
40
+ tmpdir .ensure ("adir/b/conftest.py" ).write ("b=2 ; a = 1.5" )
41
+ if request .param == "inpackage" :
42
+ tmpdir .ensure ("adir/__init__.py" )
43
+ tmpdir .ensure ("adir/b/__init__.py" )
44
+
45
+ yield tmpdir
46
+
47
+ @pytest .fixture (autouse = True )
48
+ def restore (self ):
49
+ """Restore sys.modules to prevent ConftestImportFailure when run randomly."""
50
+ snapmods = SysModulesSnapshot ()
51
+ snappath = SysPathsSnapshot ()
52
+ yield
53
+ snapmods .restore ()
54
+ snappath .restore ()
55
+
45
56
def test_basic_init (self , basedir ):
46
57
conftest = PytestPluginManager ()
47
58
p = basedir .join ("adir" )
0 commit comments