generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
5 changed files
with
160 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
tests/integration/test_snapshot_option_include_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def testcases(): | ||
return { | ||
"used": ( | ||
""" | ||
def test_used(snapshot): | ||
assert snapshot == 'used' | ||
""" | ||
), | ||
"unused": ( | ||
""" | ||
def test_unused(snapshot): | ||
assert snapshot == 'unused' | ||
""" | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def extra_testcases(): | ||
return { | ||
"extra_a": ( | ||
""" | ||
def test_extra_a(snapshot): | ||
assert snapshot == 'extra_a' | ||
""" | ||
), | ||
"extra_b": ( | ||
""" | ||
def test_extra_b(snapshot): | ||
assert snapshot == 'extra_b' | ||
""" | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def run_testfiles_with_update(testdir): | ||
def run_testfiles_with_update_impl(**testfiles): | ||
testdir.makepyfile( | ||
**{ | ||
filename: "\n\n".join(cases.values()) | ||
for (filename, cases) in testfiles.items() | ||
} | ||
) | ||
result = testdir.runpytest("-v", "--snapshot-update") | ||
result.stdout.re_match_lines((r"[0-9]+ snapshots generated\.")) | ||
return testdir | ||
|
||
return run_testfiles_with_update_impl | ||
|
||
|
||
@pytest.mark.parametrize( | ||
( | ||
"options", | ||
"expected_status_code", | ||
), | ||
( | ||
(("-v", "--snapshot-details"), 1), | ||
(("-v", "--snapshot-details", "--snapshot-warn-unused"), 0), | ||
), | ||
) | ||
def test_unused_snapshots_details( | ||
options, expected_status_code, run_testfiles_with_update, testcases | ||
): | ||
testdir = run_testfiles_with_update(test_file=testcases) | ||
testdir.makepyfile(test_file=testcases["used"]) | ||
|
||
result = testdir.runpytest(*options) | ||
result.stdout.re_match_lines( | ||
( | ||
r"1 snapshot passed\. 1 snapshot unused\.", | ||
r"Unused test_unused \(__snapshots__[\\/]test_file.ambr\)", | ||
r"Re-run pytest with --snapshot-update to delete unused snapshots\.", | ||
) | ||
) | ||
assert result.ret == expected_status_code | ||
|
||
|
||
def test_unused_snapshots_details_multiple_tests( | ||
run_testfiles_with_update, testcases, extra_testcases | ||
): | ||
testdir = run_testfiles_with_update( | ||
test_file=testcases, test_second_file=extra_testcases | ||
) | ||
testdir.makepyfile( | ||
test_file="\n\n".join(testcases.values()), | ||
test_second_file="", | ||
) | ||
|
||
result = testdir.runpytest("-v", "--snapshot-details") | ||
result.stdout.re_match_lines( | ||
( | ||
r"2 snapshots passed\. 2 snapshots unused\.", | ||
r"Unused test_extra_a, test_extra_b " | ||
r"\(__snapshots__[\\/]test_second_file.ambr\)", | ||
r"Re-run pytest with --snapshot-update to delete unused snapshots\.", | ||
) | ||
) | ||
assert result.ret == 1 | ||
|
||
|
||
def test_unused_snapshots_details_multiple_locations( | ||
run_testfiles_with_update, testcases, extra_testcases | ||
): | ||
testdir = run_testfiles_with_update( | ||
test_file=testcases, test_second_file=extra_testcases | ||
) | ||
testdir.makepyfile( | ||
test_file=testcases["used"], | ||
test_second_file=extra_testcases["extra_a"], | ||
) | ||
|
||
result = testdir.runpytest("-v", "--snapshot-details") | ||
result.stdout.re_match_lines_random( | ||
( | ||
r"2 snapshots passed\. 2 snapshots unused\.", | ||
r"Unused test_extra_b \(__snapshots__[\\/]test_second_file.ambr\)", | ||
r"Unused test_unused \(__snapshots__[\\/]test_file.ambr\)", | ||
r"Re-run pytest with --snapshot-update to delete unused snapshots\.", | ||
) | ||
) | ||
assert result.ret == 1 | ||
|
||
|
||
def test_unused_snapshots_details_no_details_on_deletion( | ||
run_testfiles_with_update, testcases | ||
): | ||
testdir = run_testfiles_with_update(test_file=testcases) | ||
testdir.makepyfile(test_file=testcases["used"]) | ||
|
||
result = testdir.runpytest("-v", "--snapshot-details", "--snapshot-update") | ||
result.stdout.re_match_lines( | ||
( | ||
r"1 snapshot passed\. 1 unused snapshot deleted\.", | ||
r"Deleted test_unused \(__snapshots__[\\/]test_file.ambr\)", | ||
) | ||
) | ||
assert result.ret == 0 |