@@ -274,10 +274,8 @@ def __init__(self, pyfuncitem):
274
274
self .fixturename = None
275
275
#: Scope string, one of "function", "class", "module", "session"
276
276
self .scope = "function"
277
- # rename both attributes below because their key has changed; better an attribute error
278
- # than subtle key misses; also backward incompatibility
279
- self ._fixture_values = {} # (argname, scope) -> fixture value
280
- self ._fixture_defs = {} # (argname, scope) -> FixtureDef
277
+ self ._fixture_values = {} # argname -> fixture value
278
+ self ._fixture_defs = {} # argname -> FixtureDef
281
279
fixtureinfo = pyfuncitem ._fixtureinfo
282
280
self ._arg2fixturedefs = fixtureinfo .name2fixturedefs .copy ()
283
281
self ._arg2index = {}
@@ -294,31 +292,20 @@ def node(self):
294
292
return self ._getscopeitem (self .scope )
295
293
296
294
297
- def _getnextfixturedef (self , argname , scope ):
298
- def trygetfixturedefs (argname ):
299
- fixturedefs = self ._arg2fixturedefs .get (argname , None )
300
- if fixturedefs is None :
301
- fixturedefs = self ._arg2fixturedefs .get (argname + ':' + scope , None )
302
- return fixturedefs
303
-
304
- fixturedefs = trygetfixturedefs (argname )
295
+ def _getnextfixturedef (self , argname ):
296
+ fixturedefs = self ._arg2fixturedefs .get (argname , None )
305
297
if fixturedefs is None :
306
298
# we arrive here because of a a dynamic call to
307
299
# getfixturevalue(argname) usage which was naturally
308
300
# not known at parsing/collection time
309
301
parentid = self ._pyfuncitem .parent .nodeid
310
302
fixturedefs = self ._fixturemanager .getfixturedefs (argname , parentid )
311
- if fixturedefs :
312
- self ._arg2fixturedefs [argname ] = fixturedefs
313
- fixturedefs_by_argname = self ._fixturemanager .getfixturedefs_multiple_scopes (argname , parentid )
314
- if fixturedefs_by_argname :
315
- self ._arg2fixturedefs .update (fixturedefs_by_argname )
316
- fixturedefs = trygetfixturedefs (argname )
303
+ self ._arg2fixturedefs [argname ] = fixturedefs
317
304
# fixturedefs list is immutable so we maintain a decreasing index
318
- index = self ._arg2index .get (( argname , scope ) , 0 ) - 1
305
+ index = self ._arg2index .get (argname , 0 ) - 1
319
306
if fixturedefs is None or (- index > len (fixturedefs )):
320
307
raise FixtureLookupError (argname , self )
321
- self ._arg2index [( argname , scope ) ] = index
308
+ self ._arg2index [argname ] = index
322
309
return fixturedefs [index ]
323
310
324
311
@property
@@ -458,10 +445,10 @@ def getfuncargvalue(self, argname):
458
445
459
446
def _get_active_fixturedef (self , argname ):
460
447
try :
461
- return self ._fixture_defs [( argname , self . scope ) ]
448
+ return self ._fixture_defs [argname ]
462
449
except KeyError :
463
450
try :
464
- fixturedef = self ._getnextfixturedef (argname , self . scope )
451
+ fixturedef = self ._getnextfixturedef (argname )
465
452
except FixtureLookupError :
466
453
if argname == "request" :
467
454
class PseudoFixtureDef :
@@ -472,8 +459,8 @@ class PseudoFixtureDef:
472
459
# remove indent to prevent the python3 exception
473
460
# from leaking into the call
474
461
result = self ._getfixturevalue (fixturedef )
475
- self ._fixture_values [( argname , self . scope ) ] = result
476
- self ._fixture_defs [( argname , self . scope ) ] = fixturedef
462
+ self ._fixture_values [argname ] = result
463
+ self ._fixture_defs [argname ] = fixturedef
477
464
return fixturedef
478
465
479
466
def _get_fixturestack (self ):
@@ -615,16 +602,6 @@ def scopemismatch(currentscope, newscope):
615
602
return scopes .index (newscope ) > scopes .index (currentscope )
616
603
617
604
618
- def strip_invocation_scope_suffix (name ):
619
- """Remove the invocation-scope suffix from the given name.
620
-
621
- Invocation scope fixtures have their scope in the name of the fixture.
622
- For example, "monkeypatch:session". This function strips the suffix
623
- returning the user-frienldy name of the fixture.
624
- """
625
- return name .split (':' )[0 ]
626
-
627
-
628
605
class FixtureLookupError (LookupError ):
629
606
""" could not return a requested Fixture (missing or invalid). """
630
607
def __init__ (self , argname , request , msg = None ):
@@ -664,7 +641,6 @@ def formatrepr(self):
664
641
parentid = self .request ._pyfuncitem .parent .nodeid
665
642
for name , fixturedefs in fm ._arg2fixturedefs .items ():
666
643
faclist = list (fm ._matchfactories (fixturedefs , parentid ))
667
- name = strip_invocation_scope_suffix (name )
668
644
if faclist and name not in available :
669
645
available .append (name )
670
646
msg = "fixture %r not found" % (self .argname ,)
@@ -847,7 +823,7 @@ def fixture(scope="function", params=None, autouse=False, ids=None, name=None):
847
823
function will be injected.
848
824
849
825
:arg scope: the scope for which this fixture is shared, one of
850
- "function" (default), "class", "module", "session" or "invocation ".
826
+ "function" (default), "class", "module" or "session ".
851
827
852
828
:arg params: an optional list of parameters which will cause multiple
853
829
invocations of the fixture function and all of the tests
@@ -1029,11 +1005,6 @@ def merge(otherlist):
1029
1005
if fixturedefs :
1030
1006
arg2fixturedefs [argname ] = fixturedefs
1031
1007
merge (fixturedefs [- 1 ].argnames )
1032
- fixturedefs_by_argname = self .getfixturedefs_multiple_scopes (argname , parentid )
1033
- if fixturedefs_by_argname :
1034
- arg2fixturedefs .update (fixturedefs_by_argname )
1035
- for fixturedefs in fixturedefs_by_argname .values ():
1036
- merge (fixturedefs [- 1 ].argnames )
1037
1008
return fixturenames_closure , arg2fixturedefs
1038
1009
1039
1010
def pytest_generate_tests (self , metafunc ):
@@ -1093,30 +1064,22 @@ def parsefactories(self, node_or_obj, nodeid=NOTSET, unittest=False):
1093
1064
'and be decorated with @pytest.fixture:\n %s' % name
1094
1065
assert not name .startswith (self ._argprefix ), msg
1095
1066
1096
- def new_fixture_def (name , scope ):
1097
- """Create and registers a new FixtureDef with given name and scope."""
1098
- fixture_def = FixtureDef (self , nodeid , name , obj ,
1099
- scope , marker .params ,
1100
- unittest = unittest , ids = marker .ids )
1067
+ fixture_def = FixtureDef (self , nodeid , name , obj ,
1068
+ marker .scope , marker .params ,
1069
+ unittest = unittest , ids = marker .ids )
1101
1070
1102
- faclist = self ._arg2fixturedefs .setdefault (name , [])
1103
- if fixture_def .has_location :
1104
- faclist .append (fixture_def )
1105
- else :
1106
- # fixturedefs with no location are at the front
1107
- # so this inserts the current fixturedef after the
1108
- # existing fixturedefs from external plugins but
1109
- # before the fixturedefs provided in conftests.
1110
- i = len ([f for f in faclist if not f .has_location ])
1111
- faclist .insert (i , fixture_def )
1112
- if marker .autouse :
1113
- autousenames .append (name )
1114
-
1115
- if marker .scope == 'invocation' :
1116
- for new_scope in scopes :
1117
- new_fixture_def (name + ':{0}' .format (new_scope ), new_scope )
1071
+ faclist = self ._arg2fixturedefs .setdefault (name , [])
1072
+ if fixture_def .has_location :
1073
+ faclist .append (fixture_def )
1118
1074
else :
1119
- new_fixture_def (name , marker .scope )
1075
+ # fixturedefs with no location are at the front
1076
+ # so this inserts the current fixturedef after the
1077
+ # existing fixturedefs from external plugins but
1078
+ # before the fixturedefs provided in conftests.
1079
+ i = len ([f for f in faclist if not f .has_location ])
1080
+ faclist .insert (i , fixture_def )
1081
+ if marker .autouse :
1082
+ autousenames .append (name )
1120
1083
1121
1084
if autousenames :
1122
1085
self ._nodeid_and_autousenames .append ((nodeid or '' , autousenames ))
@@ -1141,23 +1104,3 @@ def _matchfactories(self, fixturedefs, nodeid):
1141
1104
if nodeid .startswith (fixturedef .baseid ):
1142
1105
yield fixturedef
1143
1106
1144
- def getfixturedefs_multiple_scopes (self , argname , nodeid ):
1145
- """
1146
- Gets multiple scoped fixtures which are applicable to the given nodeid. Multiple scoped
1147
- fixtures are created by "invocation" scoped fixtures and have argnames in
1148
- the form: "<argname>:<scope>" (for example "tmpdir:session").
1149
-
1150
- :return: dict of "argname" -> [FixtureDef].
1151
-
1152
- Arguments similar to ``getfixturedefs``.
1153
- """
1154
- prefix = argname + ':'
1155
- fixturedefs_by_argname = dict ((k , v ) for k , v in self ._arg2fixturedefs .items ()
1156
- if k .startswith (prefix ))
1157
- if fixturedefs_by_argname :
1158
- result = {}
1159
- for argname , fixturedefs in fixturedefs_by_argname .items ():
1160
- result [argname ] = tuple (self ._matchfactories (fixturedefs , nodeid ))
1161
- return result
1162
- else :
1163
- return None
0 commit comments