Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Oct 18, 2024
1 parent 1047038 commit aaf0912
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 115 deletions.
6 changes: 3 additions & 3 deletions tests/integration/test_pytest_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_example(snapshot):
assert result.ret == 0


def test_does_not_print_empty_snapshot_report(testdir, plugin_args_fails_xdist):
def test_does_not_print_empty_snapshot_report(testdir, plugin_args):
testdir.makeconftest("")
testcase_no_snapshots = """
def test_example(snapshot):
Expand All @@ -61,15 +61,15 @@ def test_example(snapshot):
)

result = testdir.runpytest(
"-v", "test_file_no.py", "--snapshot-update", *plugin_args_fails_xdist
"-v", "test_file_no.py", "--snapshot-update", *plugin_args
)
result.stdout.re_match_lines((r".*test_file_no.py.*"))
assert "snapshot report" not in result.stdout.str()
assert "test_file_yes" not in result.stdout.str()
assert result.ret == 0

result = testdir.runpytest(
"-v", "test_file_yes.py", "--snapshot-update", *plugin_args_fails_xdist
"-v", "test_file_yes.py", "--snapshot-update", *plugin_args
)
result.stdout.re_match_lines((r".*test_file_yes.py.*", r".*snapshot report.*"))
assert result.ret == 0
12 changes: 6 additions & 6 deletions tests/integration/test_single_file_multiple_extensions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path


def test_multiple_file_extensions(testdir, plugin_args_fails_xdist):
def test_multiple_file_extensions(testdir, plugin_args):
file_extension = "ext2.ext1"

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

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

result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines((r"1 snapshot generated\."))
assert "snapshots unused" not in result.stdout.str()
assert result.ret == 0
Expand All @@ -34,13 +34,13 @@ def test_dot_in_filename(snapshot):
)
assert snapshot_file.exists()

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


def test_class_style(testdir, plugin_args_fails_xdist):
def test_class_style(testdir, plugin_args):
"""
Regression test for https://github.com/syrupy-project/syrupy/issues/717
"""
Expand All @@ -60,7 +60,7 @@ def test_foo(self, snapshot):

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

result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines((r"1 snapshot generated\."))
assert "deleted" not in result.stdout.str()
assert result.ret == 0
Expand All @@ -70,7 +70,7 @@ def test_foo(self, snapshot):
)
assert snapshot_file.exists()

result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", *plugin_args)
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snapshots unused" not in result.stdout.str()
assert result.ret == 0
16 changes: 8 additions & 8 deletions tests/integration/test_snapshot_option_include_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ def test_unused_snapshots_details(
expected_status_code,
run_testfiles_with_update,
testcases,
plugin_args_fails_xdist,
plugin_args,
):
testdir = run_testfiles_with_update(test_file=testcases)
testdir.makepyfile(test_file=testcases["used"])

result = testdir.runpytest(*options, *plugin_args_fails_xdist)
result = testdir.runpytest(*options, *plugin_args)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 snapshot unused\.",
Expand All @@ -85,7 +85,7 @@ def test_unused_snapshots_details(


def test_unused_snapshots_details_multiple_tests(
run_testfiles_with_update, testcases, extra_testcases, plugin_args_fails_xdist
run_testfiles_with_update, testcases, extra_testcases, plugin_args
):
testdir = run_testfiles_with_update(
test_file=testcases, test_second_file=extra_testcases
Expand All @@ -95,7 +95,7 @@ def test_unused_snapshots_details_multiple_tests(
test_second_file="",
)

result = testdir.runpytest("-v", "--snapshot-details", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-details", *plugin_args)
result.stdout.re_match_lines(
(
r"2 snapshots passed\. 2 snapshots unused\.",
Expand All @@ -108,7 +108,7 @@ def test_unused_snapshots_details_multiple_tests(


def test_unused_snapshots_details_multiple_locations(
run_testfiles_with_update, testcases, extra_testcases, plugin_args_fails_xdist
run_testfiles_with_update, testcases, extra_testcases, plugin_args
):
testdir = run_testfiles_with_update(
test_file=testcases, test_second_file=extra_testcases
Expand All @@ -118,7 +118,7 @@ def test_unused_snapshots_details_multiple_locations(
test_second_file=extra_testcases["extra_a"],
)

result = testdir.runpytest("-v", "--snapshot-details", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-details", *plugin_args)
result.stdout.re_match_lines_random(
(
r"2 snapshots passed\. 2 snapshots unused\.",
Expand All @@ -131,13 +131,13 @@ def test_unused_snapshots_details_multiple_locations(


def test_unused_snapshots_details_no_details_on_deletion(
run_testfiles_with_update, testcases, plugin_args_fails_xdist
run_testfiles_with_update, testcases, plugin_args
):
testdir = run_testfiles_with_update(test_file=testcases)
testdir.makepyfile(test_file=testcases["used"])

result = testdir.runpytest(
"-v", "--snapshot-details", "--snapshot-update", *plugin_args_fails_xdist
"-v", "--snapshot-details", "--snapshot-update", *plugin_args
)
result.stdout.re_match_lines(
(
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_snapshot_option_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ def run_testcases(testdir, testcases):
return testdir, testcases


def test_run_all(run_testcases, plugin_args_fails_xdist):
def test_run_all(run_testcases, plugin_args):
testdir, testcases = run_testcases
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", *plugin_args)
result.stdout.re_match_lines("2 snapshots passed")
assert result.ret == 0


def test_failure(run_testcases, plugin_args_fails_xdist):
def test_failure(run_testcases, plugin_args):
testdir, testcases = run_testcases
testdir.makepyfile(test_1=testcases["modified"])
result = testdir.runpytest("-vv", *plugin_args_fails_xdist)
result = testdir.runpytest("-vv", *plugin_args)
result.stdout.re_match_lines("1 snapshot failed. 1 snapshot passed.")
assert result.ret == 1


def test_update(run_testcases, plugin_args_fails_xdist):
def test_update(run_testcases, plugin_args):
testdir, testcases = run_testcases
testdir.makepyfile(test_1=testcases["modified"])
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
assert "Can not relate snapshot name" not in str(result.stdout)
result.stdout.re_match_lines("1 snapshot passed. 1 snapshot updated.")
assert result.ret == 0
58 changes: 22 additions & 36 deletions tests/integration/test_snapshot_option_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ def test_update_failure_shows_snapshot_diff(


def test_update_success_shows_snapshot_report(
run_testcases, testcases_updated, plugin_args_fails_xdist
run_testcases, testcases_updated, plugin_args
):
testdir = run_testcases[1]
testdir.makepyfile(**testcases_updated)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
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, plugin_args_fails_xdist
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -210,7 +210,7 @@ def test_used(snapshot, actual):
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args_fails_xdist, "-m", "parametrize"
"-v", "--snapshot-update", *plugin_args, "-m", "parametrize"
)
result.stdout.re_match_lines(
(
Expand All @@ -224,7 +224,7 @@ def test_used(snapshot, actual):


def test_update_targets_only_selected_parametrized_tests_for_update_dash_k(
run_testcases, plugin_args_fails_xdist
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -240,7 +240,7 @@ def test_used(snapshot, actual):
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args_fails_xdist, "-k", "test_used[2]"
"-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()
Expand All @@ -250,7 +250,7 @@ def test_used(snapshot, actual):


def test_update_targets_only_selected_parametrized_tests_for_removal_dash_k(
run_testcases, plugin_args_fails_xdist
run_testcases, plugin_args
):
updated_tests = {
"test_used": (
Expand All @@ -266,7 +266,7 @@ def test_used(snapshot, actual):
testdir = run_testcases[1]
testdir.makepyfile(**updated_tests)
result = testdir.runpytest(
"-v", "--snapshot-update", *plugin_args_fails_xdist, "-k", "test_used["
"-v", "--snapshot-update", *plugin_args, "-k", "test_used["
)
result.stdout.re_match_lines(
(
Expand All @@ -279,9 +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, plugin_args_fails_xdist
):
def test_update_targets_only_selected_class_tests_dash_k(testdir, plugin_args):
test_content = """
import pytest
Expand All @@ -298,15 +296,13 @@ def test_case_2(self, snapshot):
assert Path(testdir.tmpdir, "__snapshots__", "test_content.ambr").exists()

result = testdir.runpytest(
"test_content.py", "-v", *plugin_args_fails_xdist, "-k", "test_case_2"
"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, plugin_args_fails_xdist
):
def test_update_targets_only_selected_module_tests_dash_k(testdir, plugin_args):
test_content = """
import pytest
Expand All @@ -322,21 +318,19 @@ def test_case_2(snapshot):
assert Path(testdir.tmpdir, "__snapshots__", "test_content.ambr").exists()

result = testdir.runpytest(
"test_content.py", "-v", *plugin_args_fails_xdist, "-k", "test_case_2"
"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, plugin_args_fails_xdist
):
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", *plugin_args_fails_xdist
"-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()
Expand Down Expand Up @@ -368,7 +362,7 @@ def test_update_targets_only_selected_module_tests_nodes_pyargs(


def test_update_targets_only_selected_module_tests_file_for_update(
run_testcases, plugin_args_fails_xdist
run_testcases, plugin_args
):
testdir = run_testcases[1]
snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr")
Expand All @@ -384,9 +378,7 @@ def test_used(snapshot, actual):
"""
)
)
result = testdir.runpytest(
"-v", "test_used.py", "--snapshot-update", *plugin_args_fails_xdist
)
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 @@ -399,7 +391,7 @@ def test_used(snapshot, actual):


def test_update_targets_only_selected_module_tests_file_for_removal(
run_testcases, plugin_args_fails_xdist
run_testcases, plugin_args
):
testdir = run_testcases[1]
testdir.makepyfile(
Expand All @@ -412,9 +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", *plugin_args_fails_xdist
)
result = testdir.runpytest("-v", "test_used.py", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"5 unused snapshots deleted\.",
Expand All @@ -427,14 +417,12 @@ def test_used(snapshot):
assert not Path("__snapshots__", "test_used.ambr").exists()


def test_update_removes_empty_snapshot_collection_only(
run_testcases, plugin_args_fails_xdist
):
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", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"10 snapshots passed\. 1 unused snapshot deleted\.",
Expand All @@ -447,15 +435,13 @@ def test_update_removes_empty_snapshot_collection_only(
assert Path("__snapshots__", "test_used.ambr").exists()


def test_update_removes_hanging_snapshot_collection_file(
run_testcases, plugin_args_fails_xdist
):
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", *plugin_args_fails_xdist)
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines(
(
r"10 snapshots passed\. 1 unused snapshot deleted\.",
Expand Down
Loading

0 comments on commit aaf0912

Please sign in to comment.