1515import re
1616
1717import pytest
18-
19- try :
20- from _pytest import fixtures as pytest_fixtures
21- except ImportError :
22- from _pytest import python as pytest_fixtures
18+ from _pytest .fixtures import FixtureLookupError
2319
2420from . import exceptions
2521from .feature import get_feature , get_features
@@ -36,21 +32,25 @@ def find_argumented_step_fixture_name(name, type_, fixturemanager, request=None)
3632 for fixturename , fixturedefs in list (fixturemanager ._arg2fixturedefs .items ()):
3733 for fixturedef in fixturedefs :
3834 parser = getattr (fixturedef .func , "parser" , None )
39- match = parser .is_matching (name ) if parser else None
40- if match :
41- converters = getattr (fixturedef .func , "converters" , {})
42- for arg , value in parser .parse_arguments (name ).items ():
43- if arg in converters :
44- value = converters [arg ](value )
45- if request :
46- inject_fixture (request , arg , value )
47- parser_name = get_step_fixture_name (parser .name , type_ )
35+ if parser is None :
36+ continue
37+ match = parser .is_matching (name )
38+ if not match :
39+ continue
40+
41+ converters = getattr (fixturedef .func , "converters" , {})
42+ for arg , value in parser .parse_arguments (name ).items ():
43+ if arg in converters :
44+ value = converters [arg ](value )
4845 if request :
49- try :
50- request .getfixturevalue (parser_name )
51- except pytest_fixtures .FixtureLookupError :
52- continue
53- return parser_name
46+ inject_fixture (request , arg , value )
47+ parser_name = get_step_fixture_name (parser .name , type_ )
48+ if request :
49+ try :
50+ request .getfixturevalue (parser_name )
51+ except FixtureLookupError :
52+ continue
53+ return parser_name
5454
5555
5656def _find_step_function (request , step , scenario ):
@@ -67,14 +67,14 @@ def _find_step_function(request, step, scenario):
6767 try :
6868 # Simple case where no parser is used for the step
6969 return request .getfixturevalue (get_step_fixture_name (name , step .type ))
70- except pytest_fixtures . FixtureLookupError :
70+ except FixtureLookupError :
7171 try :
7272 # Could not find a fixture with the same name, let's see if there is a parser involved
7373 name = find_argumented_step_fixture_name (name , step .type , request ._fixturemanager , request )
7474 if name :
7575 return request .getfixturevalue (name )
7676 raise
77- except pytest_fixtures . FixtureLookupError :
77+ except FixtureLookupError :
7878 raise exceptions .StepDefinitionNotFoundError (
7979 f"Step definition is not found: { step } . "
8080 f'Line { step .line_number } in scenario "{ scenario .name } " in the feature "{ scenario .feature .filename } "'
0 commit comments