Skip to content

Commit

Permalink
Add tests highlighting xdist incompatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Oct 17, 2024
1 parent 809cdfc commit 92bae3f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 31 deletions.
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

# Constants for testing with extra plugin arguments
_NO_ARGS = []
_XDIST_ARGS = ["--numprocesses", "auto"]


@pytest.fixture(
params=[
_NO_ARGS,
pytest.param(
_XDIST_ARGS,
marks=pytest.mark.xfail(reason="Not currently compatible with xdist"),
),
],
ids=["no_plugin", "with_xdist"],
)
def plugin_args(request: pytest.FixtureRequest) -> list[str]:
"""Fixture to test with various plugins"""
return request.param
73 changes: 48 additions & 25 deletions tests/integration/test_snapshot_option_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ def run_testcases(testdir, testcases_initial):
return result, testdir, testcases_initial


def test_update_failure_shows_snapshot_diff(run_testcases, testcases_updated):
def test_update_failure_shows_snapshot_diff(
run_testcases, testcases_updated, plugin_args
):
testdir = run_testcases[1]
testdir.makepyfile(**testcases_updated)
result = testdir.runpytest("-vv")
result = testdir.runpytest("-vv", *plugin_args)
result.stdout.re_match_lines(
(
r".*assert snapshot == \['this', 'will', 'not', 'match'\]",
Expand Down Expand Up @@ -181,16 +183,18 @@ def test_update_failure_shows_snapshot_diff(run_testcases, testcases_updated):
assert result.ret == 1


def test_update_success_shows_snapshot_report(run_testcases, testcases_updated):
def test_update_success_shows_snapshot_report(
run_testcases, testcases_updated, plugin_args
):
testdir = run_testcases[1]
testdir.makepyfile(**testcases_updated)
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines((r"5 snapshots passed\. 5 snapshots updated\."))
assert result.ret == 0


def test_update_targets_only_selected_parametrized_tests_for_update_dash_m(
run_testcases,
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -205,7 +209,9 @@ def test_used(snapshot, actual):
}
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest("-v", "--snapshot-update", "-m", "parametrize")
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args, "-m", "parametrize"
)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 snapshot updated\. 1 unused snapshot deleted\.",
Expand All @@ -218,7 +224,7 @@ def test_used(snapshot, actual):


def test_update_targets_only_selected_parametrized_tests_for_update_dash_k(
run_testcases,
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -233,7 +239,9 @@ def test_used(snapshot, actual):
}
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest("-v", "--snapshot-update", "-k", "test_used[2]")
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args, "-k", "test_used[2]"
)
result.stdout.re_match_lines((r"1 snapshot updated\."))
assert "Deleted" not in result.stdout.str()
snapshot_path = [testdir.tmpdir, "__snapshots__"]
Expand All @@ -242,7 +250,7 @@ def test_used(snapshot, actual):


def test_update_targets_only_selected_parametrized_tests_for_removal_dash_k(
run_testcases,
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -257,7 +265,9 @@ def test_used(snapshot, actual):
}
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest("-v", "--snapshot-update", "-k", "test_used[")
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args, "-k", "test_used["
)
result.stdout.re_match_lines(
(
r"2 snapshots passed\. 1 unused snapshot deleted\.",
Expand All @@ -269,7 +279,7 @@ def test_used(snapshot, actual):
assert Path(*snapshot_path, "test_updated_1.ambr").exists()


def test_update_targets_only_selected_class_tests_dash_k(testdir):
def test_update_targets_only_selected_class_tests_dash_k(testdir, plugin_args):
test_content = """
import pytest
Expand All @@ -285,12 +295,14 @@ def test_case_2(self, snapshot):
testdir.runpytest("-v", "--snapshot-update")
assert Path(testdir.tmpdir, "__snapshots__", "test_content.ambr").exists()

result = testdir.runpytest("test_content.py", "-v", "-k test_case_2")
result = testdir.runpytest(
"test_content.py", "-v", *plugin_args, "-k", "test_case_2"
)
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snaphot unused" not in result.stdout.str()


def test_update_targets_only_selected_module_tests_dash_k(testdir):
def test_update_targets_only_selected_module_tests_dash_k(testdir, plugin_args):
test_content = """
import pytest
Expand All @@ -305,17 +317,21 @@ def test_case_2(snapshot):
testdir.runpytest("-v", "--snapshot-update")
assert Path(testdir.tmpdir, "__snapshots__", "test_content.ambr").exists()

result = testdir.runpytest("test_content.py", "-v", "-k test_case_2")
result = testdir.runpytest(
"test_content.py", "-v", *plugin_args, "-k", "test_case_2"
)
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snaphot unused" not in result.stdout.str()


def test_update_targets_only_selected_module_tests_nodes(run_testcases):
def test_update_targets_only_selected_module_tests_nodes(run_testcases, plugin_args):
testdir = run_testcases[1]
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
testdir.makefile(".ambr", **{str(snapfile_empty): ""})
testfile = Path(testdir.tmpdir, "test_used.py")
result = testdir.runpytest("-v", f"{testfile}::test_used", "--snapshot-update")
result = testdir.runpytest(
"-v", f"{testfile}::test_used", "--snapshot-update", *plugin_args
)
result.stdout.re_match_lines((r"3 snapshots passed\."))
assert "unused" not in result.stdout.str()
assert "updated" not in result.stdout.str()
Expand All @@ -324,13 +340,16 @@ def test_update_targets_only_selected_module_tests_nodes(run_testcases):
assert snapfile_empty.exists()


def test_update_targets_only_selected_module_tests_nodes_pyargs(run_testcases):
def test_update_targets_only_selected_module_tests_nodes_pyargs(
run_testcases, plugin_args
):
testdir = run_testcases[1]
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
testdir.makefile(".ambr", **{str(snapfile_empty): ""})
result = testdir.runpytest(
"-v",
"--snapshot-update",
*plugin_args,
"--pyargs",
"test_used::test_used",
)
Expand All @@ -342,7 +361,9 @@ def test_update_targets_only_selected_module_tests_nodes_pyargs(run_testcases):
assert snapfile_empty.exists()


def test_update_targets_only_selected_module_tests_file_for_update(run_testcases):
def test_update_targets_only_selected_module_tests_file_for_update(
run_testcases, plugin_args
):
testdir = run_testcases[1]
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
testdir.makefile(".ambr", **{str(snapfile_empty): ""})
Expand All @@ -357,7 +378,7 @@ def test_used(snapshot, actual):
"""
)
)
result = testdir.runpytest("-v", "test_used.py", "--snapshot-update")
result = testdir.runpytest("-v", "test_used.py", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"3 snapshots passed\. 2 unused snapshots deleted\.",
Expand All @@ -369,7 +390,9 @@ def test_used(snapshot, actual):
assert Path("__snapshots__", "test_used.ambr").exists()


def test_update_targets_only_selected_module_tests_file_for_removal(run_testcases):
def test_update_targets_only_selected_module_tests_file_for_removal(
run_testcases, plugin_args
):
testdir = run_testcases[1]
testdir.makepyfile(
test_used=(
Expand All @@ -381,7 +404,7 @@ def test_used(snapshot):
)
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
testdir.makefile(".ambr", **{str(snapfile_empty): ""})
result = testdir.runpytest("-v", "test_used.py", "--snapshot-update")
result = testdir.runpytest("-v", "test_used.py", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"5 unused snapshots deleted\.",
Expand All @@ -394,12 +417,12 @@ def test_used(snapshot):
assert not Path("__snapshots__", "test_used.ambr").exists()


def test_update_removes_empty_snapshot_collection_only(run_testcases):
def test_update_removes_empty_snapshot_collection_only(run_testcases, plugin_args):
testdir = run_testcases[1]
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
testdir.makefile(".ambr", **{str(snapfile_empty): ""})
assert snapfile_empty.exists()
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"10 snapshots passed\. 1 unused snapshot deleted\.",
Expand All @@ -412,13 +435,13 @@ def test_update_removes_empty_snapshot_collection_only(run_testcases):
assert Path("__snapshots__", "test_used.ambr").exists()


def test_update_removes_hanging_snapshot_collection_file(run_testcases):
def test_update_removes_hanging_snapshot_collection_file(run_testcases, plugin_args):
testdir = run_testcases[1]
snapfile_used = Path("__snapshots__", "test_used.ambr")
snapfile_hanging = Path("__snapshots__", "hanging_snapfile.abc")
testdir.makefile(".abc", **{str(snapfile_hanging): ""})
assert snapfile_hanging.exists()
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"10 snapshots passed\. 1 unused snapshot deleted\.",
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_snapshot_option_warn_unused.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def run_testcases(testdir, testcases):
return testdir, testcases


def test_unused_snapshots_failure(run_testcases):
def test_unused_snapshots_failure(run_testcases, plugin_args):
testdir, testcases = run_testcases
testdir.makepyfile(test_file=testcases["used"])

result = testdir.runpytest("-v")
result = testdir.runpytest("-v", *plugin_args)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 snapshot unused\.",
Expand All @@ -42,11 +42,11 @@ def test_unused_snapshots_failure(run_testcases):
assert result.ret == 1


def test_unused_snapshots_warning(run_testcases):
def test_unused_snapshots_warning(run_testcases, plugin_args):
testdir, testcases = run_testcases
testdir.makepyfile(test_file=testcases["used"])

result = testdir.runpytest("-v", "--snapshot-warn-unused")
result = testdir.runpytest("-v", "--snapshot-warn-unused", *plugin_args)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 snapshot unused\.",
Expand All @@ -56,11 +56,11 @@ def test_unused_snapshots_warning(run_testcases):
assert result.ret == 0


def test_unused_snapshots_deletion(run_testcases):
def test_unused_snapshots_deletion(run_testcases, plugin_args):
testdir, testcases = run_testcases
testdir.makepyfile(test_file=testcases["used"])

result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 unused snapshot deleted\.",
Expand Down

0 comments on commit 92bae3f

Please sign in to comment.