Skip to content

Commit 4c6d3e7

Browse files
committed
Add tests highlighting xdist incompatibilities
1 parent 809cdfc commit 4c6d3e7

16 files changed

+236
-135
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ dist,
9595
[tool.pytest.ini_options]
9696
addopts = '-p syrupy -p pytester -p no:legacypath --doctest-modules'
9797
testpaths = ['tests']
98+
xfail_strict = true
9899

99100
[tool.coverage.run]
100101
source = ['./src']

tests/conftest.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
# Constants for testing with extra plugin arguments
4+
_NO_ARGS = []
5+
_XDIST_ZERO = ["--numprocesses", "0"]
6+
_XDIST_TWO = ["--numprocesses", "2"]
7+
8+
9+
@pytest.fixture(
10+
params=[_NO_ARGS, _XDIST_ZERO, _XDIST_TWO],
11+
ids=["no_plugin", "xdist_zero", "xdist_two"],
12+
)
13+
def plugin_args(request: pytest.FixtureRequest) -> list[str]:
14+
"""Fixture to test with various plugins"""
15+
return request.param
16+
17+
18+
@pytest.fixture(
19+
params=[
20+
_NO_ARGS,
21+
_XDIST_ZERO,
22+
pytest.param(
23+
_XDIST_TWO,
24+
marks=pytest.mark.xfail(reason="Not currently compatible with xdist"),
25+
),
26+
],
27+
ids=["no_plugin", "xdist_zero", "xdist_two"],
28+
)
29+
def plugin_args_fails_xdist(request: pytest.FixtureRequest) -> list[str]:
30+
"""Fixture to test with various plugins, but expected to fail xdist"""
31+
return request.param

tests/integration/test_custom_comparator.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,37 @@ def generate_snapshots(testdir, testcases_initial):
4848
return result, testdir, testcases_initial
4949

5050

51-
@pytest.mark.xfail(strict=False)
5251
def test_generated_snapshots(generate_snapshots):
5352
result = generate_snapshots[0]
5453
result.stdout.re_match_lines((r"1 snapshot generated\."))
5554
assert "snapshots unused" not in result.stdout.str()
5655
assert result.ret == 0
5756

5857

59-
@pytest.mark.xfail(strict=False)
60-
def test_approximate_match(generate_snapshots):
58+
def test_approximate_match(generate_snapshots, plugin_args_fails_xdist):
6159
testdir = generate_snapshots[1]
6260
testdir.makepyfile(
6361
test_file="""
6462
def test_passed_custom(snapshot_custom):
6563
assert snapshot_custom == 3.2
6664
"""
6765
)
68-
result = testdir.runpytest("-v")
66+
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
6967
result.stdout.re_match_lines((r"test_file.py::test_passed_custom PASSED"))
7068
assert result.ret == 0
7169

7270

73-
@pytest.mark.xfail(strict=False)
74-
def test_failed_snapshots(generate_snapshots):
71+
def test_failed_snapshots(generate_snapshots, plugin_args_fails_xdist):
7572
testdir = generate_snapshots[1]
7673
testdir.makepyfile(test_file=generate_snapshots[2]["failed"])
77-
result = testdir.runpytest("-v")
74+
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
7875
result.stdout.re_match_lines((r"1 snapshot failed\."))
7976
assert result.ret == 1
8077

8178

82-
@pytest.mark.xfail(strict=False)
83-
def test_updated_snapshots(generate_snapshots):
79+
def test_updated_snapshots(generate_snapshots, plugin_args_fails_xdist):
8480
_, testdir, initial = generate_snapshots
8581
testdir.makepyfile(test_file=initial["failed"])
86-
result = testdir.runpytest("-v", "--snapshot-update")
82+
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
8783
result.stdout.re_match_lines((r"1 snapshot updated\."))
8884
assert result.ret == 0

tests/integration/test_pycharm_patch.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,37 @@ def __init__(self, expected, actual, msg=None, preformated=False, real_exception
2323

2424

2525
@pytest.mark.filterwarnings("default")
26-
def test_logs_a_warning_if_unable_to_apply_patch(testdir):
26+
def test_logs_a_warning_if_unable_to_apply_patch(testdir, plugin_args):
2727
testdir.makepyfile(
2828
test_file="""
2929
def test_case(snapshot):
3030
assert snapshot == [1, 2]
3131
"""
3232
)
33-
testdir.runpytest("-v", "--snapshot-update")
33+
testdir.runpytest("-v", "--snapshot-update", *plugin_args)
3434
testdir.makepyfile(
3535
test_file="""
3636
def test_case(snapshot):
3737
assert snapshot == [1, 2, 3]
3838
"""
3939
)
4040

41-
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff")
41+
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff", *plugin_args)
4242
result.assert_outcomes(failed=1, passed=0, warnings=1)
4343

4444

4545
@pytest.mark.filterwarnings("default")
46-
def test_patches_pycharm_diff_tools_when_flag_set(testdir, mock_teamcity_diff_tools):
46+
def test_patches_pycharm_diff_tools_when_flag_set(
47+
testdir, mock_teamcity_diff_tools, plugin_args
48+
):
4749
# Generate initial snapshot
4850
testdir.makepyfile(
4951
test_file="""
5052
def test_case(snapshot):
5153
assert snapshot == [1, 2]
5254
"""
5355
)
54-
testdir.runpytest("-v", "--snapshot-update")
56+
testdir.runpytest("-v", "--snapshot-update", *plugin_args)
5557

5658
# Generate diff and mimic EqualsAssertionError being thrown
5759
testdir.makepyfile(
@@ -70,7 +72,7 @@ def test_case(snapshot):
7072
"""
7173
)
7274

73-
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff")
75+
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff", *plugin_args)
7476
# No warnings because patch should have been successful
7577
result.assert_outcomes(failed=1, passed=0, warnings=0)
7678

@@ -85,7 +87,7 @@ def test_case(snapshot):
8587

8688
@pytest.mark.filterwarnings("default")
8789
def test_patches_pycharm_diff_tools_when_flag_set_and_snapshot_on_right(
88-
testdir, mock_teamcity_diff_tools
90+
testdir, mock_teamcity_diff_tools, plugin_args
8991
):
9092
# Generate initial snapshot
9193
testdir.makepyfile(
@@ -94,7 +96,7 @@ def test_case(snapshot):
9496
assert [1, 2] == snapshot
9597
"""
9698
)
97-
testdir.runpytest("-v", "--snapshot-update")
99+
testdir.runpytest("-v", "--snapshot-update", *plugin_args)
98100

99101
# Generate diff and mimic EqualsAssertionError being thrown
100102
testdir.makepyfile(
@@ -113,7 +115,7 @@ def test_case(snapshot):
113115
"""
114116
)
115117

116-
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff")
118+
result = testdir.runpytest("-v", "--snapshot-patch-pycharm-diff", *plugin_args)
117119
# No warnings because patch should have been successful
118120
result.assert_outcomes(failed=1, passed=0, warnings=0)
119121

@@ -128,7 +130,7 @@ def test_case(snapshot):
128130

129131
@pytest.mark.filterwarnings("default")
130132
def test_it_does_not_patch_pycharm_diff_tools_by_default(
131-
testdir, mock_teamcity_diff_tools
133+
testdir, mock_teamcity_diff_tools, plugin_args
132134
):
133135
# Generate initial snapshot
134136
testdir.makepyfile(
@@ -137,7 +139,7 @@ def test_case(snapshot):
137139
assert snapshot == [1, 2]
138140
"""
139141
)
140-
testdir.runpytest("-v", "--snapshot-update")
142+
testdir.runpytest("-v", "--snapshot-update", *plugin_args)
141143

142144
# Generate diff and mimic EqualsAssertionError being thrown
143145
testdir.makepyfile(
@@ -156,7 +158,7 @@ def test_case(snapshot):
156158
"""
157159
)
158160

159-
result = testdir.runpytest("-v")
161+
result = testdir.runpytest("-v", *plugin_args)
160162
# No warnings because patch should have been successful
161163
result.assert_outcomes(failed=1, passed=0, warnings=0)
162164

@@ -170,7 +172,9 @@ def test_case(snapshot):
170172

171173

172174
@pytest.mark.filterwarnings("default")
173-
def test_it_has_no_impact_on_non_syrupy_assertions(testdir, mock_teamcity_diff_tools):
175+
def test_it_has_no_impact_on_non_syrupy_assertions(
176+
testdir, mock_teamcity_diff_tools, plugin_args
177+
):
174178
# Generate diff and mimic EqualsAssertionError being thrown
175179
testdir.makepyfile(
176180
test_file="""
@@ -188,7 +192,7 @@ def test_case():
188192
"""
189193
)
190194

191-
result = testdir.runpytest("-v")
195+
result = testdir.runpytest("-v", *plugin_args)
192196
# No warnings because patch should have been successful
193197
result.assert_outcomes(failed=1, passed=0, warnings=0)
194198

@@ -202,7 +206,7 @@ def test_case():
202206

203207
@pytest.mark.filterwarnings("default")
204208
def test_has_no_impact_on_real_exceptions_that_are_not_assertion_errors(
205-
testdir, mock_teamcity_diff_tools
209+
testdir, mock_teamcity_diff_tools, plugin_args
206210
):
207211
# Generate diff and mimic EqualsAssertionError being thrown
208212
testdir.makepyfile(
@@ -225,7 +229,7 @@ def test_case():
225229
"""
226230
)
227231

228-
result = testdir.runpytest("-v")
232+
result = testdir.runpytest("-v", *plugin_args)
229233
# No warnings because patch should have been successful
230234
result.assert_outcomes(failed=1, passed=0, warnings=0)
231235

tests/integration/test_pytest_extension.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def test_ignores_non_function_nodes(testdir):
1+
def test_ignores_non_function_nodes(testdir, plugin_args):
22
conftest = """
33
import pytest
44
@@ -23,25 +23,30 @@ def test_example(snapshot):
2323
"""
2424
testdir.makeconftest(conftest)
2525
testdir.makepyfile(test_file=testcase)
26-
result = testdir.runpytest("test_file.py", "-v", "--snapshot-update")
26+
result = testdir.runpytest("test_file.py", "-v", "--snapshot-update", *plugin_args)
2727
result.stdout.re_match_lines((r".*test_file.py::CUSTOM.*"))
2828
assert result.ret == 0
2929

3030

31-
def test_handles_pyargs_non_module_when_both_given(testdir):
31+
def test_handles_pyargs_non_module_when_both_given(testdir, plugin_args):
3232
testdir.makeconftest("")
3333
testcase = """
3434
def test_example(snapshot):
3535
assert snapshot == 1
3636
"""
3737
testdir.makepyfile(test_file=testcase)
3838
result = testdir.runpytest(
39-
"-v", "test_file.py", "--pyargs", "test_file", "--snapshot-update"
39+
"-v",
40+
"test_file.py",
41+
"--pyargs",
42+
"test_file",
43+
"--snapshot-update",
44+
*plugin_args,
4045
)
4146
assert result.ret == 0
4247

4348

44-
def test_does_not_print_empty_snapshot_report(testdir):
49+
def test_does_not_print_empty_snapshot_report(testdir, plugin_args_fails_xdist):
4550
testdir.makeconftest("")
4651
testcase_no_snapshots = """
4752
def test_example(snapshot):
@@ -55,12 +60,16 @@ def test_example(snapshot):
5560
test_file_no=testcase_no_snapshots, test_file_yes=testcase_yes_snapshots
5661
)
5762

58-
result = testdir.runpytest("-v", "test_file_no.py", "--snapshot-update")
63+
result = testdir.runpytest(
64+
"-v", "test_file_no.py", "--snapshot-update", *plugin_args_fails_xdist
65+
)
5966
result.stdout.re_match_lines((r".*test_file_no.py.*"))
6067
assert "snapshot report" not in result.stdout.str()
6168
assert "test_file_yes" not in result.stdout.str()
6269
assert result.ret == 0
6370

64-
result = testdir.runpytest("-v", "test_file_yes.py", "--snapshot-update")
71+
result = testdir.runpytest(
72+
"-v", "test_file_yes.py", "--snapshot-update", *plugin_args_fails_xdist
73+
)
6574
result.stdout.re_match_lines((r".*test_file_yes.py.*", r".*snapshot report.*"))
6675
assert result.ret == 0

tests/integration/test_single_file_multiple_extensions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22

33

4-
def test_multiple_file_extensions(testdir):
4+
def test_multiple_file_extensions(testdir, plugin_args_fails_xdist):
55
file_extension = "ext2.ext1"
66

77
testcase = f"""
@@ -21,7 +21,7 @@ def test_dot_in_filename(snapshot):
2121

2222
test_file: Path = testdir.makepyfile(test_file=testcase)
2323

24-
result = testdir.runpytest("-v", "--snapshot-update")
24+
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
2525
result.stdout.re_match_lines((r"1 snapshot generated\."))
2626
assert "snapshots unused" not in result.stdout.str()
2727
assert result.ret == 0
@@ -34,13 +34,13 @@ def test_dot_in_filename(snapshot):
3434
)
3535
assert snapshot_file.exists()
3636

37-
result = testdir.runpytest("-v")
37+
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
3838
result.stdout.re_match_lines((r"1 snapshot passed\."))
3939
assert "snapshots unused" not in result.stdout.str()
4040
assert result.ret == 0
4141

4242

43-
def test_class_style(testdir):
43+
def test_class_style(testdir, plugin_args_fails_xdist):
4444
"""
4545
Regression test for https://github.com/syrupy-project/syrupy/issues/717
4646
"""
@@ -60,7 +60,7 @@ def test_foo(self, snapshot):
6060

6161
test_file: Path = testdir.makepyfile(test_file=testcase)
6262

63-
result = testdir.runpytest("-v", "--snapshot-update")
63+
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
6464
result.stdout.re_match_lines((r"1 snapshot generated\."))
6565
assert "deleted" not in result.stdout.str()
6666
assert result.ret == 0
@@ -70,7 +70,7 @@ def test_foo(self, snapshot):
7070
)
7171
assert snapshot_file.exists()
7272

73-
result = testdir.runpytest("-v")
73+
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
7474
result.stdout.re_match_lines((r"1 snapshot passed\."))
7575
assert "snapshots unused" not in result.stdout.str()
7676
assert result.ret == 0

0 commit comments

Comments
 (0)