Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ dist,
[tool.pytest.ini_options]
addopts = '-p syrupy -p pytester -p no:legacypath --doctest-modules'
testpaths = ['tests']
xfail_strict = true

[tool.coverage.run]
source = ['./src']
Expand Down
33 changes: 33 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from typing import List

import pytest

# Constants for testing with extra plugin arguments
_NO_ARGS = []
_XDIST_ZERO = ["--numprocesses", "0"]
_XDIST_TWO = ["--numprocesses", "2"]


@pytest.fixture(
params=[_NO_ARGS, _XDIST_ZERO, _XDIST_TWO],
ids=["no_plugin", "xdist_zero", "xdist_two"],
)
def plugin_args(request: pytest.FixtureRequest) -> List[str]:
"""Fixture to test with various plugins"""
return request.param


@pytest.fixture(
params=[
_NO_ARGS,
_XDIST_ZERO,
pytest.param(
_XDIST_TWO,
marks=pytest.mark.xfail(reason="Not currently compatible with xdist"),
),
],
ids=["no_plugin", "xdist_zero", "xdist_two"],
)
def plugin_args_fails_xdist(request: pytest.FixtureRequest) -> List[str]:
"""Fixture to test with various plugins, but expected to fail xdist"""
return request.param
8 changes: 4 additions & 4 deletions tests/integration/test_custom_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def test_generated_snapshots(generate_snapshots):


@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

Expand All @@ -80,9 +80,9 @@ def test_failed_snapshots(generate_snapshots):


@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
23 changes: 16 additions & 7 deletions tests/integration/test_pytest_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_ignores_non_function_nodes(testdir):
def test_ignores_non_function_nodes(testdir, plugin_args):
conftest = """
import pytest
Expand All @@ -23,25 +23,30 @@ def test_example(snapshot):
"""
testdir.makeconftest(conftest)
testdir.makepyfile(test_file=testcase)
result = testdir.runpytest("test_file.py", "-v", "--snapshot-update")
result = testdir.runpytest("test_file.py", "-v", "--snapshot-update", *plugin_args)
result.stdout.re_match_lines((r".*test_file.py::CUSTOM.*"))
assert result.ret == 0


def test_handles_pyargs_non_module_when_both_given(testdir):
def test_handles_pyargs_non_module_when_both_given(testdir, plugin_args):
testdir.makeconftest("")
testcase = """
def test_example(snapshot):
assert snapshot == 1
"""
testdir.makepyfile(test_file=testcase)
result = testdir.runpytest(
"-v", "test_file.py", "--pyargs", "test_file", "--snapshot-update"
"-v",
"test_file.py",
"--pyargs",
"test_file",
"--snapshot-update",
*plugin_args,
)
assert result.ret == 0


def test_does_not_print_empty_snapshot_report(testdir):
def test_does_not_print_empty_snapshot_report(testdir, plugin_args_fails_xdist):
testdir.makeconftest("")
testcase_no_snapshots = """
def test_example(snapshot):
Expand All @@ -55,12 +60,16 @@ def test_example(snapshot):
test_file_no=testcase_no_snapshots, test_file_yes=testcase_yes_snapshots
)

result = testdir.runpytest("-v", "test_file_no.py", "--snapshot-update")
result = testdir.runpytest(
"-v", "test_file_no.py", "--snapshot-update", *plugin_args_fails_xdist
)
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")
result = testdir.runpytest(
"-v", "test_file_yes.py", "--snapshot-update", *plugin_args_fails_xdist
)
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):
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
Loading
Loading