Skip to content

Commit

Permalink
Identify more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Oct 18, 2024
1 parent 8b939c4 commit 565cf9c
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 78 deletions.
16 changes: 6 additions & 10 deletions tests/integration/test_custom_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,37 @@ def generate_snapshots(testdir, testcases_initial):
return result, testdir, testcases_initial


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


@pytest.mark.xfail(strict=False)
def test_approximate_match(generate_snapshots):
def test_approximate_match(generate_snapshots, plugin_args_fails_xdist):
testdir = generate_snapshots[1]
testdir.makepyfile(
test_file="""
def test_passed_custom(snapshot_custom):
assert snapshot_custom == 3.2
"""
)
result = testdir.runpytest("-v")
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result.stdout.re_match_lines((r"test_file.py::test_passed_custom PASSED"))
assert result.ret == 0


@pytest.mark.xfail(strict=False)
def test_failed_snapshots(generate_snapshots):
def test_failed_snapshots(generate_snapshots, plugin_args_fails_xdist):
testdir = generate_snapshots[1]
testdir.makepyfile(test_file=generate_snapshots[2]["failed"])
result = testdir.runpytest("-v")
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result.stdout.re_match_lines((r"1 snapshot failed\."))
assert result.ret == 1


@pytest.mark.xfail(strict=False)
def test_updated_snapshots(generate_snapshots):
def test_updated_snapshots(generate_snapshots, plugin_args_fails_xdist):
_, testdir, initial = generate_snapshots
testdir.makepyfile(test_file=initial["failed"])
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result.stdout.re_match_lines((r"1 snapshot updated\."))
assert result.ret == 0
36 changes: 20 additions & 16 deletions tests/integration/test_pycharm_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,37 @@ def __init__(self, expected, actual, msg=None, preformated=False, real_exception


@pytest.mark.filterwarnings("default")
def test_logs_a_warning_if_unable_to_apply_patch(testdir):
def test_logs_a_warning_if_unable_to_apply_patch(testdir, plugin_args):
testdir.makepyfile(
test_file="""
def test_case(snapshot):
assert snapshot == [1, 2]
"""
)
testdir.runpytest("-v", "--snapshot-update")
testdir.runpytest("-v", "--snapshot-update", *plugin_args)
testdir.makepyfile(
test_file="""
def test_case(snapshot):
assert snapshot == [1, 2, 3]
"""
)

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


@pytest.mark.filterwarnings("default")
def test_patches_pycharm_diff_tools_when_flag_set(testdir, mock_teamcity_diff_tools):
def test_patches_pycharm_diff_tools_when_flag_set(
testdir, mock_teamcity_diff_tools, plugin_args
):
# Generate initial snapshot
testdir.makepyfile(
test_file="""
def test_case(snapshot):
assert snapshot == [1, 2]
"""
)
testdir.runpytest("-v", "--snapshot-update")
testdir.runpytest("-v", "--snapshot-update", *plugin_args)

# Generate diff and mimic EqualsAssertionError being thrown
testdir.makepyfile(
Expand All @@ -70,7 +72,7 @@ def test_case(snapshot):
"""
)

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

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

@pytest.mark.filterwarnings("default")
def test_patches_pycharm_diff_tools_when_flag_set_and_snapshot_on_right(
testdir, mock_teamcity_diff_tools
testdir, mock_teamcity_diff_tools, plugin_args
):
# Generate initial snapshot
testdir.makepyfile(
Expand All @@ -94,7 +96,7 @@ def test_case(snapshot):
assert [1, 2] == snapshot
"""
)
testdir.runpytest("-v", "--snapshot-update")
testdir.runpytest("-v", "--snapshot-update", *plugin_args)

# Generate diff and mimic EqualsAssertionError being thrown
testdir.makepyfile(
Expand All @@ -113,7 +115,7 @@ def test_case(snapshot):
"""
)

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

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

@pytest.mark.filterwarnings("default")
def test_it_does_not_patch_pycharm_diff_tools_by_default(
testdir, mock_teamcity_diff_tools
testdir, mock_teamcity_diff_tools, plugin_args
):
# Generate initial snapshot
testdir.makepyfile(
Expand All @@ -137,7 +139,7 @@ def test_case(snapshot):
assert snapshot == [1, 2]
"""
)
testdir.runpytest("-v", "--snapshot-update")
testdir.runpytest("-v", "--snapshot-update", *plugin_args)

# Generate diff and mimic EqualsAssertionError being thrown
testdir.makepyfile(
Expand All @@ -156,7 +158,7 @@ def test_case(snapshot):
"""
)

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

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


@pytest.mark.filterwarnings("default")
def test_it_has_no_impact_on_non_syrupy_assertions(testdir, mock_teamcity_diff_tools):
def test_it_has_no_impact_on_non_syrupy_assertions(
testdir, mock_teamcity_diff_tools, plugin_args
):
# Generate diff and mimic EqualsAssertionError being thrown
testdir.makepyfile(
test_file="""
Expand All @@ -188,7 +192,7 @@ def test_case():
"""
)

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

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

@pytest.mark.filterwarnings("default")
def test_has_no_impact_on_real_exceptions_that_are_not_assertion_errors(
testdir, mock_teamcity_diff_tools
testdir, mock_teamcity_diff_tools, plugin_args
):
# Generate diff and mimic EqualsAssertionError being thrown
testdir.makepyfile(
Expand All @@ -225,7 +229,7 @@ def test_case():
"""
)

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

Expand Down
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):
def test_multiple_file_extensions(testdir, plugin_args_fails_xdist):
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")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
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")
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
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):
def test_class_style(testdir, plugin_args_fails_xdist):
"""
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")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
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")
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result.stdout.re_match_lines((r"1 snapshot passed\."))
assert "snapshots unused" not in result.stdout.str()
assert result.ret == 0
22 changes: 14 additions & 8 deletions tests/integration/test_snapshot_option_include_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ def run_testfiles_with_update_impl(**testfiles):
),
)
def test_unused_snapshots_details(
options, expected_status_code, run_testfiles_with_update, testcases
options,
expected_status_code,
run_testfiles_with_update,
testcases,
plugin_args_fails_xdist,
):
testdir = run_testfiles_with_update(test_file=testcases)
testdir.makepyfile(test_file=testcases["used"])

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


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

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


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

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


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

result = testdir.runpytest("-v", "--snapshot-details", "--snapshot-update")
result = testdir.runpytest(
"-v", "--snapshot-details", "--snapshot-update", *plugin_args_fails_xdist
)
result.stdout.re_match_lines(
(
r"1 snapshot passed\. 1 unused snapshot deleted\.",
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_snapshot_outside_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ def test_generated_snapshots(generate_snapshots):
assert result.ret == 0


def test_unmatched_snapshots(generate_snapshots):
def test_unmatched_snapshots(generate_snapshots, plugin_args_fails_xdist):
_, testdir, testcases = generate_snapshots
testdir.makepyfile(test_file=testcases["one"])
result = testdir.runpytest("-v")
result = testdir.runpytest("-v", *plugin_args_fails_xdist)
result.stdout.re_match_lines((r"1 snapshot passed. 1 snapshot unused\."))
assert result.ret == 1


def test_updated_snapshots_partial_delete(generate_snapshots):
def test_updated_snapshots_partial_delete(generate_snapshots, plugin_args_fails_xdist):
_, testdir, testcases = generate_snapshots
testdir.makepyfile(test_file=testcases["one"])
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result.stdout.re_match_lines(r"1 snapshot passed. 1 unused snapshot deleted\.")
assert result.ret == 0


def test_updated_snapshots_full_delete(generate_snapshots):
def test_updated_snapshots_full_delete(generate_snapshots, plugin_args_fails_xdist):
_, testdir, testcases = generate_snapshots
testdir.makepyfile(test_file=testcases["zero"])
result = testdir.runpytest("-v", "--snapshot-update")
result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist)
result.stdout.re_match_lines(r"2 unused snapshots deleted\.")
assert result.ret == 0
Loading

0 comments on commit 565cf9c

Please sign in to comment.