1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
import pytest
@pytest.fixture
def testcases():
return {
"used": (
"""
def test_used(snapshot):
assert snapshot == 'used'
"""
),
"raise-skipped": (
"""
import pytest
def test_skipped(snapshot):
pytest.skip("Skipping...")
assert snapshot == 'unused'
"""
),
"mark-skipped": (
"""
import pytest
@pytest.mark.skip
def test_skipped(snapshot):
assert snapshot == 'unused'
"""
),
"not-skipped": (
"""
def test_skipped(snapshot):
assert snapshot == 'unused'
"""
),
}
@pytest.fixture
def run_testcases(testdir, testcases):
pyfile_content = "\n\n".join([testcases["used"], testcases["not-skipped"]])
testdir.makepyfile(test_file=pyfile_content)
result = testdir.runpytest("-v", "--snapshot-update")
result.stdout.re_match_lines(r"2 snapshots generated\.")
return testdir, 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", *plugin_args_fails_xdist)
result.stdout.re_match_lines(r"1 snapshot passed\.$")
assert result.ret == 0
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", *plugin_args_fails_xdist)
result.stdout.re_match_lines(r"1 snapshot passed\.$")
assert result.ret == 0
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", *plugin_args_fails_xdist)
result.stdout.re_match_lines(r"1 snapshot passed\.$")
assert result.ret == 0
|