@@ -22,6 +22,7 @@ def __init__(self):
22
22
self .confcutdir = str (confcutdir )
23
23
self .noconftest = False
24
24
self .pyargs = False
25
+ self .importmode = "prepend"
25
26
26
27
conftest ._set_initial_conftests (Namespace ())
27
28
@@ -42,35 +43,38 @@ def basedir(self, request, tmpdir_factory):
42
43
def test_basic_init (self , basedir ):
43
44
conftest = PytestPluginManager ()
44
45
p = basedir .join ("adir" )
45
- assert conftest ._rget_with_confmod ("a" , p )[1 ] == 1
46
+ assert conftest ._rget_with_confmod ("a" , p , importmode = "prepend" )[1 ] == 1
46
47
47
48
def test_immediate_initialiation_and_incremental_are_the_same (self , basedir ):
48
49
conftest = PytestPluginManager ()
49
50
assert not len (conftest ._dirpath2confmods )
50
- conftest ._getconftestmodules (basedir )
51
+ conftest ._getconftestmodules (basedir , importmode = "prepend" )
51
52
snap1 = len (conftest ._dirpath2confmods )
52
53
assert snap1 == 1
53
- conftest ._getconftestmodules (basedir .join ("adir" ))
54
+ conftest ._getconftestmodules (basedir .join ("adir" ), importmode = "prepend" )
54
55
assert len (conftest ._dirpath2confmods ) == snap1 + 1
55
- conftest ._getconftestmodules (basedir .join ("b" ))
56
+ conftest ._getconftestmodules (basedir .join ("b" ), importmode = "prepend" )
56
57
assert len (conftest ._dirpath2confmods ) == snap1 + 2
57
58
58
59
def test_value_access_not_existing (self , basedir ):
59
60
conftest = ConftestWithSetinitial (basedir )
60
61
with pytest .raises (KeyError ):
61
- conftest ._rget_with_confmod ("a" , basedir )
62
+ conftest ._rget_with_confmod ("a" , basedir , importmode = "prepend" )
62
63
63
64
def test_value_access_by_path (self , basedir ):
64
65
conftest = ConftestWithSetinitial (basedir )
65
66
adir = basedir .join ("adir" )
66
- assert conftest ._rget_with_confmod ("a" , adir )[1 ] == 1
67
- assert conftest ._rget_with_confmod ("a" , adir .join ("b" ))[1 ] == 1.5
67
+ assert conftest ._rget_with_confmod ("a" , adir , importmode = "prepend" )[1 ] == 1
68
+ assert (
69
+ conftest ._rget_with_confmod ("a" , adir .join ("b" ), importmode = "prepend" )[1 ]
70
+ == 1.5
71
+ )
68
72
69
73
def test_value_access_with_confmod (self , basedir ):
70
74
startdir = basedir .join ("adir" , "b" )
71
75
startdir .ensure ("xx" , dir = True )
72
76
conftest = ConftestWithSetinitial (startdir )
73
- mod , value = conftest ._rget_with_confmod ("a" , startdir )
77
+ mod , value = conftest ._rget_with_confmod ("a" , startdir , importmode = "prepend" )
74
78
assert value == 1.5
75
79
path = py .path .local (mod .__file__ )
76
80
assert path .dirpath () == basedir .join ("adir" , "b" )
@@ -90,7 +94,7 @@ def test_doubledash_considered(testdir):
90
94
conf .ensure ("conftest.py" )
91
95
conftest = PytestPluginManager ()
92
96
conftest_setinitial (conftest , [conf .basename , conf .basename ])
93
- values = conftest ._getconftestmodules (conf )
97
+ values = conftest ._getconftestmodules (conf , importmode = "prepend" )
94
98
assert len (values ) == 1
95
99
96
100
@@ -113,13 +117,13 @@ def test_conftest_global_import(testdir):
113
117
import py, pytest
114
118
from _pytest.config import PytestPluginManager
115
119
conf = PytestPluginManager()
116
- mod = conf._importconftest(py.path.local("conftest.py"))
120
+ mod = conf._importconftest(py.path.local("conftest.py"), importmode="prepend" )
117
121
assert mod.x == 3
118
122
import conftest
119
123
assert conftest is mod, (conftest, mod)
120
124
subconf = py.path.local().ensure("sub", "conftest.py")
121
125
subconf.write("y=4")
122
- mod2 = conf._importconftest(subconf)
126
+ mod2 = conf._importconftest(subconf, importmode="prepend" )
123
127
assert mod != mod2
124
128
assert mod2.y == 4
125
129
import conftest
@@ -135,17 +139,17 @@ def test_conftestcutdir(testdir):
135
139
p = testdir .mkdir ("x" )
136
140
conftest = PytestPluginManager ()
137
141
conftest_setinitial (conftest , [testdir .tmpdir ], confcutdir = p )
138
- values = conftest ._getconftestmodules (p )
142
+ values = conftest ._getconftestmodules (p , importmode = "prepend" )
139
143
assert len (values ) == 0
140
- values = conftest ._getconftestmodules (conf .dirpath ())
144
+ values = conftest ._getconftestmodules (conf .dirpath (), importmode = "prepend" )
141
145
assert len (values ) == 0
142
146
assert conf not in conftest ._conftestpath2mod
143
147
# but we can still import a conftest directly
144
- conftest ._importconftest (conf )
145
- values = conftest ._getconftestmodules (conf .dirpath ())
148
+ conftest ._importconftest (conf , importmode = "prepend" )
149
+ values = conftest ._getconftestmodules (conf .dirpath (), importmode = "prepend" )
146
150
assert values [0 ].__file__ .startswith (str (conf ))
147
151
# and all sub paths get updated properly
148
- values = conftest ._getconftestmodules (p )
152
+ values = conftest ._getconftestmodules (p , importmode = "prepend" )
149
153
assert len (values ) == 1
150
154
assert values [0 ].__file__ .startswith (str (conf ))
151
155
@@ -154,7 +158,7 @@ def test_conftestcutdir_inplace_considered(testdir):
154
158
conf = testdir .makeconftest ("" )
155
159
conftest = PytestPluginManager ()
156
160
conftest_setinitial (conftest , [conf .dirpath ()], confcutdir = conf .dirpath ())
157
- values = conftest ._getconftestmodules (conf .dirpath ())
161
+ values = conftest ._getconftestmodules (conf .dirpath (), importmode = "prepend" )
158
162
assert len (values ) == 1
159
163
assert values [0 ].__file__ .startswith (str (conf ))
160
164
@@ -348,13 +352,13 @@ def test_conftest_import_order(testdir, monkeypatch):
348
352
ct2 = sub .join ("conftest.py" )
349
353
ct2 .write ("" )
350
354
351
- def impct (p ):
355
+ def impct (p , importmode ):
352
356
return p
353
357
354
358
conftest = PytestPluginManager ()
355
359
conftest ._confcutdir = testdir .tmpdir
356
360
monkeypatch .setattr (conftest , "_importconftest" , impct )
357
- assert conftest ._getconftestmodules (sub ) == [ct1 , ct2 ]
361
+ assert conftest ._getconftestmodules (sub , importmode = "prepend" ) == [ct1 , ct2 ]
358
362
359
363
360
364
def test_fixture_dependency (testdir ):
0 commit comments