1
1
"""Test feature base dir."""
2
2
import pytest
3
3
4
+ NOT_EXISTING_FEATURE_PATHS = [
5
+ '.' ,
6
+ '/does/not/exist/' ,
7
+ ]
8
+
4
9
5
10
@pytest .mark .parametrize (
6
- 'base_dir' , [
7
- '.' ,
8
- '/does/not/exist/' ,
9
- ]
11
+ 'base_dir' , NOT_EXISTING_FEATURE_PATHS
10
12
)
11
13
def test_feature_path_not_found (testdir , base_dir ):
12
14
"""Test feature base dir."""
13
15
prepare_testdir (testdir , base_dir )
14
16
15
- result = testdir .runpytest ('-k' , 'test_not_found ' )
16
- result .assert_outcomes (passed = 1 )
17
+ result = testdir .runpytest ('-k' , 'test_not_found_by_ini ' )
18
+ result .assert_outcomes (passed = 2 )
17
19
18
20
19
21
def test_feature_path_ok (testdir ):
20
22
base_dir = 'features'
21
23
prepare_testdir (testdir , base_dir )
22
24
23
- result = testdir .runpytest ('-k' , 'test_ok' )
24
- result .assert_outcomes (passed = 1 )
25
+ result = testdir .runpytest ('-k' , 'test_ok_by_ini' )
26
+ result .assert_outcomes (passed = 2 )
27
+
25
28
29
+ def test_feature_path_by_param_not_found (testdir ):
30
+ """As param takes precendence even if ini config is correct it should fail
31
+ if passed param is incorrect"""
32
+ base_dir = 'features'
33
+ prepare_testdir (testdir , base_dir )
26
34
27
- def prepare_testdir (testdir , base_dir ):
35
+ result = testdir .runpytest ('-k' , 'test_not_found_by_param' )
36
+ result .assert_outcomes (passed = 4 )
37
+
38
+
39
+ @pytest .mark .parametrize (
40
+ 'base_dir' , NOT_EXISTING_FEATURE_PATHS
41
+ )
42
+ def test_feature_path_by_param_ok (testdir , base_dir ):
43
+ """If ini config is incorrect but param path is fine it should be able
44
+ to find features"""
45
+ prepare_testdir (testdir , base_dir )
46
+
47
+ result = testdir .runpytest ('-k' , 'test_ok_by_param' )
48
+ result .assert_outcomes (passed = 2 )
49
+
50
+
51
+ def prepare_testdir (testdir , ini_base_dir ):
28
52
testdir .makeini ("""
29
53
[pytest]
30
54
bdd_feature_base_dir={}
31
- """ .format (base_dir ))
55
+ """ .format (ini_base_dir ))
32
56
33
57
feature_file = testdir .mkdir ('features' ).join ('steps.feature' )
34
58
feature_file .write ("""
@@ -37,24 +61,71 @@ def prepare_testdir(testdir, base_dir):
37
61
""" )
38
62
39
63
testdir .makepyfile ("""
40
- import pytest
41
- from pytest_bdd import scenario
42
64
import os.path
43
65
66
+ import pytest
67
+
68
+ from pytest_bdd import scenario, scenarios
69
+
70
+ FEATURE = 'steps.feature'
71
+
72
+
44
73
@pytest.fixture(params=[
45
74
'When scenario found',
46
75
])
47
76
def scenario_name(request):
48
77
return request.param
49
78
50
- def test_not_found(scenario_name):
51
- base_dir = '{}'
52
- print("BS: %s" % base_dir)
79
+
80
+ @pytest.mark.parametrize(
81
+ 'multiple', [True, False]
82
+ )
83
+ def test_not_found_by_ini(scenario_name, multiple):
53
84
with pytest.raises(IOError) as exc:
54
- scenario('steps.feature', scenario_name)
55
- assert os.path.abspath(os.path.join(base_dir, 'steps.feature')) in str(exc.value)
85
+ if multiple:
86
+ scenarios(FEATURE)
87
+ else:
88
+ scenario(FEATURE, scenario_name)
89
+ assert os.path.abspath(os.path.join('{}', FEATURE)) in str(exc.value)
90
+
56
91
57
- def test_ok(scenario_name):
92
+ @pytest.mark.parametrize(
93
+ 'multiple', [True, False]
94
+ )
95
+ def test_ok_by_ini(scenario_name, multiple):
58
96
# Shouldn't raise any exception
59
- scenario('steps.feature', scenario_name)
60
- """ .format (base_dir ))
97
+ if multiple:
98
+ scenarios(FEATURE)
99
+ else:
100
+ scenario(FEATURE, scenario_name)
101
+
102
+
103
+ @pytest.mark.parametrize(
104
+ 'multiple', [True, False]
105
+ )
106
+ @pytest.mark.parametrize(
107
+ 'param_base_dir', [
108
+ '.',
109
+ '/does/not/exist/',
110
+ ]
111
+ )
112
+ def test_not_found_by_param(scenario_name, param_base_dir, multiple):
113
+ with pytest.raises(IOError) as exc:
114
+ if multiple:
115
+ scenarios(FEATURE, feature_base_dir=param_base_dir)
116
+ else:
117
+ scenario(FEATURE, scenario_name, feature_base_dir=param_base_dir)
118
+ assert os.path.abspath(os.path.join(param_base_dir, FEATURE)) in str(exc.value)
119
+
120
+
121
+ @pytest.mark.parametrize(
122
+ 'multiple', [True, False]
123
+ )
124
+ def test_ok_by_param(scenario_name, multiple):
125
+ # Shouldn't raise any exception no matter of bdd_feature_base_dir in ini
126
+ if multiple:
127
+ scenarios(FEATURE, feature_base_dir='features')
128
+ else:
129
+ scenario(FEATURE, scenario_name, feature_base_dir='features')
130
+
131
+ """ .format (ini_base_dir ))
0 commit comments