Skip to content

Commit 1a749b3

Browse files
Bastian-KrauseEmantor
authored andcommitted
tests/test_flags: move env config creation to factory fixture
Every test creates a bare env config with or without feature. A future commit will introduce even more tests that will do this. So move the env config creation to a factory fixture that takes the desired features as an argument. Signed-off-by: Bastian Krause <bst@pengutronix.de>
1 parent bd0cff0 commit 1a749b3

File tree

1 file changed

+31
-68
lines changed

1 file changed

+31
-68
lines changed

tests/test_flags.py

Lines changed: 31 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1+
import pytest
12
import pexpect
23

3-
def test_with_feature(tmpdir):
4-
conf = tmpdir.join("config.yaml")
5-
conf.write(
4+
@pytest.fixture
5+
def env_feature_config(tmpdir):
6+
def _env_feature_config(features):
7+
conf = tmpdir.join("config.yaml")
8+
conf.write(
69
"""
7-
targets:
8-
test1:
9-
features:
10-
- test
11-
drivers: {}
10+
targets:
11+
test1:
12+
features:
1213
"""
13-
)
14+
)
15+
for feature in features:
16+
conf.write(f" - {feature}\n", "a")
17+
if not features:
18+
conf.write(" {}\n", "a")
19+
20+
return conf
21+
22+
yield _env_feature_config
23+
24+
def test_with_feature(tmpdir, env_feature_config):
25+
conf = env_feature_config(["test"])
1426
test = tmpdir.join("test.py")
1527
test.write(
1628
"""
@@ -28,17 +40,8 @@ def test(env):
2840
spawn.close()
2941
assert spawn.exitstatus == 0
3042

31-
def test_skip_feature(tmpdir):
32-
conf = tmpdir.join("config.yaml")
33-
conf.write(
34-
"""
35-
targets:
36-
test1:
37-
features:
38-
- test
39-
drivers: {}
40-
"""
41-
)
43+
def test_skip_feature(tmpdir, env_feature_config):
44+
conf = env_feature_config(["test"])
4245
test = tmpdir.join("test2.py")
4346
test.write(
4447
"""
@@ -56,17 +59,8 @@ def test(env):
5659
spawn.close()
5760
assert spawn.exitstatus == 0
5861

59-
def test_skip_feature_list(tmpdir):
60-
conf = tmpdir.join("config.yaml")
61-
conf.write(
62-
"""
63-
targets:
64-
test1:
65-
features:
66-
- test
67-
drivers: {}
68-
"""
69-
)
62+
def test_skip_feature_list(tmpdir, env_feature_config):
63+
conf = env_feature_config(["test"])
7064
test = tmpdir.join("test2.py")
7165
test.write(
7266
"""
@@ -84,18 +78,8 @@ def test(env):
8478
spawn.close()
8579
assert spawn.exitstatus == 0
8680

87-
def test_match_feature_list(tmpdir):
88-
conf = tmpdir.join("config.yaml")
89-
conf.write(
90-
"""
91-
targets:
92-
test1:
93-
features:
94-
- test1
95-
- test2
96-
drivers: {}
97-
"""
98-
)
81+
def test_match_feature_list(tmpdir, env_feature_config):
82+
conf = env_feature_config(["test1", "test2"])
9983
test = tmpdir.join("test2.py")
10084
test.write(
10185
"""
@@ -113,19 +97,8 @@ def test(env):
11397
spawn.close()
11498
assert spawn.exitstatus == 0
11599

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-
)
100+
def test_match_multi_feature_source(tmpdir, env_feature_config):
101+
conf = env_feature_config(["test1", "test2", "test3"])
129102
test = tmpdir.join("test.py")
130103
test.write(
131104
"""
@@ -147,18 +120,8 @@ def test(self, env):
147120
spawn.close()
148121
assert spawn.exitstatus == 0
149122

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-
)
123+
def test_skip_multi_feature_source(tmpdir, env_feature_config):
124+
conf = env_feature_config(["test1", "test3"])
162125
test = tmpdir.join("test.py")
163126
test.write(
164127
"""

0 commit comments

Comments
 (0)