File tree Expand file tree Collapse file tree 3 files changed +78
-11
lines changed Expand file tree Collapse file tree 3 files changed +78
-11
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ Release 0.5.0 (unreleased)
4
4
New Features in 0.5.0
5
5
~~~~~~~~~~~~~~~~~~~~~
6
6
- Support for Eaton ePDU added, and can be used as a NetworkPowerPort.
7
+ - Consider a combination of multiple "lg_feature" markers instead of
8
+ considering only the closest marker.
7
9
8
10
Bug fixes in 0.5.0
9
11
~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change @@ -53,7 +53,6 @@ def pytest_configure(config):
53
53
def pytest_collection_modifyitems (config , items ):
54
54
"""This function matches function feature flags with those found in the
55
55
environment and disables the item if no match is found"""
56
- have_feature = []
57
56
env = config ._labgrid_env
58
57
59
58
if not env :
@@ -62,17 +61,16 @@ def pytest_collection_modifyitems(config, items):
62
61
have_feature = env .get_features () | env .get_target_features ()
63
62
64
63
for item in items :
65
- marker = item .get_closest_marker ("lg_feature" )
66
- if not marker :
67
- continue
64
+ want_feature = set ()
68
65
69
- arg = marker .args [0 ]
70
- if isinstance (arg , str ):
71
- want_feature = set ([arg ])
72
- elif isinstance (arg , list ):
73
- want_feature = set (arg )
74
- else :
75
- raise Exception ("Unsupported feature argument type" )
66
+ for marker in item .iter_markers ("lg_feature" ):
67
+ arg = marker .args [0 ]
68
+ if isinstance (arg , str ):
69
+ want_feature .add (arg )
70
+ elif isinstance (arg , list ):
71
+ want_feature .update (arg )
72
+ else :
73
+ raise Exception ("Unsupported feature argument type" )
76
74
missing_feature = want_feature - have_feature
77
75
if missing_feature :
78
76
if len (missing_feature ) == 1 :
Original file line number Diff line number Diff line change @@ -112,3 +112,70 @@ def test(env):
112
112
spawn .expect (pexpect .EOF )
113
113
spawn .close ()
114
114
assert spawn .exitstatus == 0
115
+
116
+ def test_match_multi_feature_source (tmpdir ):
117
+ conf = tmpdir .join ("config.yaml" )
118
+ conf .write (
119
+ """
120
+ targets:
121
+ test1:
122
+ features:
123
+ - test1
124
+ - test2
125
+ - test3
126
+ drivers: {}
127
+ """
128
+ )
129
+ test = tmpdir .join ("test.py" )
130
+ test .write (
131
+ """
132
+ import pytest
133
+
134
+ pytestmark = pytest.mark.lg_feature("test1")
135
+
136
+ @pytest.mark.lg_feature("test2")
137
+ class TestMulti:
138
+ @pytest.mark.lg_feature("test3")
139
+ def test(self, env):
140
+ assert True
141
+ """
142
+ )
143
+
144
+ with pexpect .spawn (f'pytest --lg-env { conf } { test } ' ) as spawn :
145
+ spawn .expect ("1 passed" )
146
+ spawn .expect (pexpect .EOF )
147
+ spawn .close ()
148
+ assert spawn .exitstatus == 0
149
+
150
+ def test_skip_multi_feature_source (tmpdir ):
151
+ conf = tmpdir .join ("config.yaml" )
152
+ conf .write (
153
+ """
154
+ targets:
155
+ test1:
156
+ features:
157
+ - test1
158
+ - test3
159
+ drivers: {}
160
+ """
161
+ )
162
+ test = tmpdir .join ("test.py" )
163
+ test .write (
164
+ """
165
+ import pytest
166
+
167
+ pytestmark = pytest.mark.lg_feature("test1")
168
+
169
+ @pytest.mark.lg_feature("test2")
170
+ class TestMulti:
171
+ @pytest.mark.lg_feature("test3")
172
+ def test(self, env):
173
+ assert True
174
+ """
175
+ )
176
+
177
+ with pexpect .spawn (f'pytest --lg-env { conf } { test } ' ) as spawn :
178
+ spawn .expect ("1 skipped" )
179
+ spawn .expect (pexpect .EOF )
180
+ spawn .close ()
181
+ assert spawn .exitstatus == 0
You can’t perform that action at this time.
0 commit comments