diff --git a/pyproject.toml b/pyproject.toml index 85c53b61..3b622798 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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'] diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..e8baadab --- /dev/null +++ b/tests/conftest.py @@ -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 diff --git a/tests/integration/test_custom_comparator.py b/tests/integration/test_custom_comparator.py index 8f6d87a6..d88ebf9e 100644 --- a/tests/integration/test_custom_comparator.py +++ b/tests/integration/test_custom_comparator.py @@ -57,7 +57,7 @@ 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=""" @@ -65,7 +65,7 @@ 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 @@ -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 diff --git a/tests/integration/test_pycharm_patch.py b/tests/integration/test_pycharm_patch.py index e1e6a9fb..f5ea6193 100644 --- a/tests/integration/test_pycharm_patch.py +++ b/tests/integration/test_pycharm_patch.py @@ -23,14 +23,14 @@ 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): @@ -38,12 +38,14 @@ def test_case(snapshot): """ ) - 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=""" @@ -51,7 +53,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( @@ -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) @@ -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( @@ -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( @@ -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) @@ -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( @@ -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( @@ -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) @@ -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=""" @@ -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) @@ -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( @@ -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) diff --git a/tests/integration/test_pytest_extension.py b/tests/integration/test_pytest_extension.py index d69ca434..d8186fa7 100644 --- a/tests/integration/test_pytest_extension.py +++ b/tests/integration/test_pytest_extension.py @@ -1,4 +1,4 @@ -def test_ignores_non_function_nodes(testdir): +def test_ignores_non_function_nodes(testdir, plugin_args): conftest = """ import pytest @@ -23,12 +23,12 @@ 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): @@ -36,12 +36,17 @@ def test_example(snapshot): """ 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): @@ -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 diff --git a/tests/integration/test_single_file_multiple_extensions.py b/tests/integration/test_single_file_multiple_extensions.py index c9932bfd..8c4fb0dc 100644 --- a/tests/integration/test_single_file_multiple_extensions.py +++ b/tests/integration/test_single_file_multiple_extensions.py @@ -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""" @@ -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 @@ -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 """ @@ -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 @@ -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 diff --git a/tests/integration/test_snapshot_option_include_details.py b/tests/integration/test_snapshot_option_include_details.py index 8f2365c3..e2224c64 100644 --- a/tests/integration/test_snapshot_option_include_details.py +++ b/tests/integration/test_snapshot_option_include_details.py @@ -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\.", @@ -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 @@ -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\.", @@ -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 @@ -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\.", @@ -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\.", diff --git a/tests/integration/test_snapshot_option_name.py b/tests/integration/test_snapshot_option_name.py index 9533df42..fd58df57 100644 --- a/tests/integration/test_snapshot_option_name.py +++ b/tests/integration/test_snapshot_option_name.py @@ -32,32 +32,25 @@ def run_testcases(testdir, testcases): return testdir, testcases -def test_run_all(run_testcases): +def test_run_all(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases - result = testdir.runpytest( - "-v", - ) + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines("2 snapshots passed") assert result.ret == 0 -def test_failure(run_testcases): +def test_failure(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases testdir.makepyfile(test_1=testcases["modified"]) - result = testdir.runpytest( - "-v", - ) + result = testdir.runpytest("-vv", *plugin_args_fails_xdist) result.stdout.re_match_lines("1 snapshot failed. 1 snapshot passed.") assert result.ret == 1 -def test_update(run_testcases): +def test_update(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases testdir.makepyfile(test_1=testcases["modified"]) - result = testdir.runpytest( - "-v", - "--snapshot-update", - ) + result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist) 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 diff --git a/tests/integration/test_snapshot_option_update.py b/tests/integration/test_snapshot_option_update.py index b898c9a8..c4991f93 100644 --- a/tests/integration/test_snapshot_option_update.py +++ b/tests/integration/test_snapshot_option_update.py @@ -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_fails_xdist +): testdir = run_testcases[1] testdir.makepyfile(**testcases_updated) - result = testdir.runpytest("-vv") + result = testdir.runpytest("-vv", *plugin_args_fails_xdist) result.stdout.re_match_lines( ( r".*assert snapshot == \['this', 'will', 'not', 'match'\]", @@ -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_fails_xdist +): testdir = run_testcases[1] testdir.makepyfile(**testcases_updated) - result = testdir.runpytest("-v", "--snapshot-update") + result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist) 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_fails_xdist ): updated_tests = { "test_used": ( @@ -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_fails_xdist, "-m", "parametrize" + ) result.stdout.re_match_lines( ( r"1 snapshot passed\. 1 snapshot updated\. 1 unused snapshot deleted\.", @@ -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_fails_xdist ): updated_tests = { "test_used": ( @@ -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_fails_xdist, "-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__"] @@ -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_fails_xdist ): updated_tests = { "test_used": ( @@ -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_fails_xdist, "-k", "test_used[" + ) result.stdout.re_match_lines( ( r"2 snapshots passed\. 1 unused snapshot deleted\.", @@ -269,7 +279,9 @@ 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_fails_xdist +): test_content = """ import pytest @@ -285,12 +297,16 @@ 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_fails_xdist, "-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_fails_xdist +): test_content = """ import pytest @@ -305,17 +321,23 @@ 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_fails_xdist, "-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_fails_xdist +): 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_fails_xdist + ) result.stdout.re_match_lines((r"3 snapshots passed\.")) assert "unused" not in result.stdout.str() assert "updated" not in result.stdout.str() @@ -324,13 +346,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_fails_xdist +): 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_fails_xdist, "--pyargs", "test_used::test_used", ) @@ -342,7 +367,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_fails_xdist +): testdir = run_testcases[1] snapfile_empty = Path("__snapshots__", "empty_snapfile.ambr") testdir.makefile(".ambr", **{str(snapfile_empty): ""}) @@ -357,7 +384,9 @@ 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_fails_xdist + ) result.stdout.re_match_lines( ( r"3 snapshots passed\. 2 unused snapshots deleted\.", @@ -369,7 +398,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_fails_xdist +): testdir = run_testcases[1] testdir.makepyfile( test_used=( @@ -381,7 +412,9 @@ 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_fails_xdist + ) result.stdout.re_match_lines( ( r"5 unused snapshots deleted\.", @@ -394,12 +427,14 @@ 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_fails_xdist +): 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_fails_xdist) result.stdout.re_match_lines( ( r"10 snapshots passed\. 1 unused snapshot deleted\.", @@ -412,13 +447,15 @@ 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_fails_xdist +): 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_fails_xdist) result.stdout.re_match_lines( ( r"10 snapshots passed\. 1 unused snapshot deleted\.", diff --git a/tests/integration/test_snapshot_option_warn_unused.py b/tests/integration/test_snapshot_option_warn_unused.py index f9a36134..99442583 100644 --- a/tests/integration/test_snapshot_option_warn_unused.py +++ b/tests/integration/test_snapshot_option_warn_unused.py @@ -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_fails_xdist): testdir, testcases = run_testcases testdir.makepyfile(test_file=testcases["used"]) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines( ( r"1 snapshot passed\. 1 snapshot unused\.", @@ -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_fails_xdist): 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_fails_xdist) result.stdout.re_match_lines( ( r"1 snapshot passed\. 1 snapshot unused\.", @@ -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_fails_xdist): testdir, testcases = run_testcases testdir.makepyfile(test_file=testcases["used"]) - 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\.", diff --git a/tests/integration/test_snapshot_outside_directory.py b/tests/integration/test_snapshot_outside_directory.py index e0cafc55..87defe71 100644 --- a/tests/integration/test_snapshot_outside_directory.py +++ b/tests/integration/test_snapshot_outside_directory.py @@ -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 diff --git a/tests/integration/test_snapshot_similar_names_default.py b/tests/integration/test_snapshot_similar_names_default.py index 5ba1e18b..ea832a74 100644 --- a/tests/integration/test_snapshot_similar_names_default.py +++ b/tests/integration/test_snapshot_similar_names_default.py @@ -36,49 +36,61 @@ def run_testcases(testdir, testcases): return testdir, testcases -def test_run_all(run_testcases): +def test_run_all(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines("9 snapshots passed") assert result.ret == 0 -def test_run_single_file(run_testcases): +def test_run_single_file(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases - result = testdir.runpytest("-v", "test_1.py") + result = testdir.runpytest("-v", "test_1.py", *plugin_args_fails_xdist) result.stdout.re_match_lines("3 snapshots passed") assert result.ret == 0 -def test_run_single_test_case_in_file(run_testcases): +def test_run_single_test_case_in_file(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases - result = testdir.runpytest("-v", "test_2.py::test_a") + result = testdir.runpytest("-v", "test_2.py::test_a", *plugin_args_fails_xdist) result.stdout.re_match_lines("1 snapshot passed") assert result.ret == 0 -def test_run_all_but_one(run_testcases): +def test_run_all_but_one(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( - "-v", "--snapshot-details", "test_1.py", "test_2.py::test_a" + "-v", + "--snapshot-details", + "test_1.py", + "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("4 snapshots passed") assert result.ret == 0 -def test_run_both_files_by_node(run_testcases): +def test_run_both_files_by_node(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( - "-v", "--snapshot-details", "test_1.py::test_a", "test_2.py::test_a" + "-v", + "--snapshot-details", + "test_1.py::test_a", + "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("2 snapshots passed") assert result.ret == 0 -def test_run_both_files_by_node_2(run_testcases): +def test_run_both_files_by_node_2(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( - "-v", "--snapshot-details", "test_1.py::test_b", "test_2.py::test_a" + "-v", + "--snapshot-details", + "test_1.py::test_b", + "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("2 snapshots passed") assert result.ret == 0 diff --git a/tests/integration/test_snapshot_similar_names_file_extension.py b/tests/integration/test_snapshot_similar_names_file_extension.py index 458d4075..520baad7 100644 --- a/tests/integration/test_snapshot_similar_names_file_extension.py +++ b/tests/integration/test_snapshot_similar_names_file_extension.py @@ -41,42 +41,45 @@ def run_testcases(testdir, testcases): return testdir, testcases -def test_run_all(run_testcases): +def test_run_all(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", "--snapshot-default-extension", "syrupy.extensions.single_file.SingleFileSnapshotExtension", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("9 snapshots passed") assert result.ret == 0 -def test_run_single_file(run_testcases): +def test_run_single_file(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", "--snapshot-default-extension", "syrupy.extensions.single_file.SingleFileSnapshotExtension", "test_1.py", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("3 snapshots passed") assert result.ret == 0 -def test_run_single_test_case_in_file(run_testcases): +def test_run_single_test_case_in_file(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", "--snapshot-default-extension", "syrupy.extensions.single_file.SingleFileSnapshotExtension", "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("1 snapshot passed") assert result.ret == 0 -def test_run_all_but_one(run_testcases): +def test_run_all_but_one(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", @@ -85,12 +88,13 @@ def test_run_all_but_one(run_testcases): "syrupy.extensions.single_file.SingleFileSnapshotExtension", "test_1.py", "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("4 snapshots passed") assert result.ret == 0 -def test_run_both_files_by_node(run_testcases): +def test_run_both_files_by_node(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", @@ -99,12 +103,13 @@ def test_run_both_files_by_node(run_testcases): "syrupy.extensions.single_file.SingleFileSnapshotExtension", "test_1.py::test_a", "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("2 snapshots passed") assert result.ret == 0 -def test_run_both_files_by_node_2(run_testcases): +def test_run_both_files_by_node_2(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases result = testdir.runpytest( "-v", @@ -113,6 +118,7 @@ def test_run_both_files_by_node_2(run_testcases): "syrupy.extensions.single_file.SingleFileSnapshotExtension", "test_1.py::test_b", "test_2.py::test_a", + *plugin_args_fails_xdist, ) result.stdout.re_match_lines("2 snapshots passed") assert result.ret == 0 diff --git a/tests/integration/test_snapshot_skipped.py b/tests/integration/test_snapshot_skipped.py index c985bf80..1e276093 100644 --- a/tests/integration/test_snapshot_skipped.py +++ b/tests/integration/test_snapshot_skipped.py @@ -44,31 +44,31 @@ def run_testcases(testdir, testcases): return testdir, testcases -def test_mark_skipped_snapshots(run_testcases): +def test_mark_skipped_snapshots(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases pyfile_content = "\n\n".join([testcases["used"], testcases["mark-skipped"]]) testdir.makepyfile(test_file=pyfile_content) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines(r"1 snapshot passed\.$") assert result.ret == 0 -def test_raise_skipped_snapshots(run_testcases): +def test_raise_skipped_snapshots(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases pyfile_content = "\n\n".join([testcases["used"], testcases["raise-skipped"]]) testdir.makepyfile(test_file=pyfile_content) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines(r"1 snapshot passed\.$") assert result.ret == 0 -def test_skipped_snapshots_update(run_testcases): +def test_skipped_snapshots_update(run_testcases, plugin_args_fails_xdist): testdir, testcases = run_testcases pyfile_content = "\n\n".join([testcases["used"], testcases["raise-skipped"]]) testdir.makepyfile(test_file=pyfile_content) - 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\.$") assert result.ret == 0 diff --git a/tests/integration/test_snapshot_use_extension.py b/tests/integration/test_snapshot_use_extension.py index 375d3ad5..cfe0df26 100644 --- a/tests/integration/test_snapshot_use_extension.py +++ b/tests/integration/test_snapshot_use_extension.py @@ -94,6 +94,7 @@ def generate_snapshots(testdir, testcases_initial): return result, testdir, testcases_initial +# xdist behavior different on Windows - needs to be reviewed def test_unsaved_snapshots(testdir, testcases_initial): testdir.makepyfile(test_file=testcases_initial["passed"]) result = testdir.runpytest("-v") @@ -103,9 +104,9 @@ def test_unsaved_snapshots(testdir, testcases_initial): assert result.ret == 1 -def test_failed_snapshots(testdir, testcases_initial): +def test_failed_snapshots(testdir, testcases_initial, plugin_args_fails_xdist): testdir.makepyfile(test_file=testcases_initial["failed"]) - result = testdir.runpytest("-v", "--snapshot-update") + result = testdir.runpytest("-v", "--snapshot-update", *plugin_args_fails_xdist) result.stdout.re_match_lines((r"2 snapshots failed\.")) assert result.ret == 1 @@ -117,18 +118,22 @@ def test_generated_snapshots(generate_snapshots): assert result.ret == 0 -def test_unmatched_snapshots(generate_snapshots, testcases_updated): +def test_unmatched_snapshots( + generate_snapshots, testcases_updated, plugin_args_fails_xdist +): testdir = generate_snapshots[1] testdir.makepyfile(test_file=testcases_updated["passed"]) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines((r"1 snapshot failed\. 2 snapshots unused\.")) assert result.ret == 1 -def test_updated_snapshots(generate_snapshots, testcases_updated): +def test_updated_snapshots( + generate_snapshots, testcases_updated, plugin_args_fails_xdist +): testdir = generate_snapshots[1] testdir.makepyfile(test_file=testcases_updated["passed"]) - 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\. 2 unused snapshots deleted\.")) assert result.ret == 0 diff --git a/tests/integration/test_xfail.py b/tests/integration/test_xfail.py index 5113717f..4dee1ea1 100644 --- a/tests/integration/test_xfail.py +++ b/tests/integration/test_xfail.py @@ -1,4 +1,4 @@ -def test_no_failure_printed_if_all_failures_xfailed(testdir): +def test_no_failure_printed_if_all_failures_xfailed(testdir, plugin_args): testdir.makepyfile( test_file=( """ @@ -10,12 +10,14 @@ def test_a(snapshot): """ ) ) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args) result.stdout.no_re_match_line((r".*snapshot failed*")) assert result.ret == 0 -def test_failures_printed_if_only_some_failures_xfailed(testdir): +def test_failures_printed_if_only_some_failures_xfailed( + testdir, plugin_args_fails_xdist +): testdir.makepyfile( test_file=( """ @@ -30,13 +32,13 @@ def test_b(snapshot): """ ) ) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines((r".*1 snapshot failed*")) result.stdout.re_match_lines((r".*1 snapshot xfailed*")) assert result.ret == 1 -def test_failure_printed_if_xfail_does_not_run(testdir): +def test_failure_printed_if_xfail_does_not_run(testdir, plugin_args_fails_xdist): testdir.makepyfile( test_file=( """ @@ -48,7 +50,7 @@ def test_a(snapshot): """ ) ) - result = testdir.runpytest("-v") + result = testdir.runpytest("-v", *plugin_args_fails_xdist) result.stdout.re_match_lines((r".*1 snapshot failed*")) result.stdout.no_re_match_line((r".*1 snapshot xfailed*")) assert result.ret == 1