Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changed how --inline-snapshot=disable works in combination with xdist #93

Merged
merged 1 commit into from
May 28, 2024
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
16 changes: 9 additions & 7 deletions inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ def pytest_configure(config):
else:
flags = config.option.inline_snapshot.split(",")
flags = {flag for flag in flags if flag}
if xdist_running(config) and flags - {"disable"}:
raise pytest.UsageError(
f"--inline-snapshot={','.join(flags)} can not be combined with xdist"
)

if "disable" in flags and flags != {"disable"}:
raise pytest.UsageError(
f"--inline-snapshot=disable can not be combined with other flags ({', '.join(flags-{'disable'})})"
)

if xdist_running(config) and flags - {"disabled", "short-report", "report"}:
raise pytest.UsageError(f"inline-snapshot can not be combined with xdist")

if xdist_running(config):
_inline_snapshot._active = False

Expand Down Expand Up @@ -156,10 +157,11 @@ def pytest_assertrepr_compare(config, op, left, right):
def pytest_terminal_summary(terminalreporter, exitstatus, config):

if xdist_running(config):
terminalreporter.section("inline snapshot")
terminalreporter.write(
"INFO: inline-snapshot was disabled because you used xdist\n"
)
if flags != {"disable"}:
terminalreporter.section("inline snapshot")
terminalreporter.write(
"INFO: inline-snapshot was disabled because you used xdist\n"
)
return

if not _inline_snapshot._active:
Expand Down
48 changes: 47 additions & 1 deletion tests/test_xdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_a():
result = project.run("--inline-snapshot=create", "-n=auto")

assert "\n".join(result.stderr.lines).strip() == snapshot(
"ERROR: inline-snapshot can not be combined with xdist"
"ERROR: --inline-snapshot=create can not be combined with xdist"
)

assert result.ret == 4
Expand All @@ -37,3 +37,49 @@ def test_a():
)

assert result.ret == 0


def test_xdist_and_disable(project):

project.setup(
"""\

def test_a():
assert 1==snapshot(2)
"""
)

result = project.run("-n=auto", "--inline-snapshot=disable")

assert result.report == snapshot("")

assert result.stderr.lines == snapshot([])

assert result.ret == 1

result = project.run("-n=auto", "--inline-snapshot=fix")

assert result.report == snapshot("")

assert result.stderr.lines == snapshot(
["ERROR: --inline-snapshot=fix can not be combined with xdist", ""]
)

assert result.ret == 4

project.pyproject(
"""\
[tool.inline-snapshot]
default-flags = ["fix"]
"""
)

result = project.run("-n=auto")

assert result.report == snapshot(
"INFO: inline-snapshot was disabled because you used xdist"
)

assert result.stderr.lines == snapshot([])

assert result.ret == 0
Loading