generated from tophat/new-project-kit
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unused snapshot not filtered out when specific node
- Loading branch information
Noah Negin-Ulster
committed
Aug 18, 2021
1 parent
c8ed886
commit 9a0bef3
Showing
4 changed files
with
223 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def testcases(): | ||
return { | ||
"a": ( | ||
""" | ||
def test_a(snapshot): | ||
assert snapshot == 'a' | ||
""" | ||
), | ||
"b": ( | ||
""" | ||
def test_b(snapshot): | ||
assert snapshot == 'b' | ||
""" | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def run_testcases(testdir, testcases): | ||
pyfile_content = "\n\n".join(testcases.values()) | ||
testdir.makepyfile(test_1=pyfile_content, test_2=pyfile_content) | ||
result = testdir.runpytest("-v", "--snapshot-update") | ||
result.stdout.re_match_lines((r"4 snapshots generated\.")) | ||
return testdir, testcases | ||
|
||
|
||
def test_run_all(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest("-v") | ||
result.stdout.re_match_lines("4 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_single_file(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest("-v", "test_1.py") | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_single_test_case_in_file(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest("-v", "test_2.py::test_a") | ||
result.stdout.re_match_lines("1 snapshot passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_all_but_one(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", "--snapshot-details", "test_1.py", "test_2.py::test_a" | ||
) | ||
result.stdout.re_match_lines("3 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_both_files_by_node(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", "--snapshot-details", "test_1.py::test_a", "test_2.py::test_a" | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_both_files_by_node_2(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", "--snapshot-details", "test_1.py::test_b", "test_2.py::test_a" | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 |
110 changes: 110 additions & 0 deletions
110
tests/integration/test_snapshot_similar_names_file_extension.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,110 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def testcases(): | ||
return { | ||
"a": ( | ||
""" | ||
def test_a(snapshot): | ||
assert snapshot == b"a" | ||
""" | ||
), | ||
"b": ( | ||
""" | ||
def test_b(snapshot): | ||
assert snapshot == b"b" | ||
""" | ||
), | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def run_testcases(testdir, testcases): | ||
pyfile_content = "\n\n".join(testcases.values()) | ||
testdir.makepyfile(test_1=pyfile_content, test_2=pyfile_content) | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-update", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
) | ||
result.stdout.re_match_lines((r"4 snapshots generated\.")) | ||
return testdir, testcases | ||
|
||
|
||
def test_run_all(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
) | ||
result.stdout.re_match_lines("4 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_single_file(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
"test_1.py", | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_single_test_case_in_file(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
"test_2.py::test_a", | ||
) | ||
result.stdout.re_match_lines("1 snapshot passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_all_but_one(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-details", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
"test_1.py", | ||
"test_2.py::test_a", | ||
) | ||
result.stdout.re_match_lines("3 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_both_files_by_node(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-details", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
"test_1.py::test_a", | ||
"test_2.py::test_a", | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 | ||
|
||
|
||
def test_run_both_files_by_node_2(run_testcases): | ||
testdir, testcases = run_testcases | ||
result = testdir.runpytest( | ||
"-v", | ||
"--snapshot-details", | ||
"--snapshot-default-extension", | ||
"syrupy.extensions.single_file.SingleFileSnapshotExtension", | ||
"test_1.py::test_b", | ||
"test_2.py::test_a", | ||
) | ||
result.stdout.re_match_lines("2 snapshots passed") | ||
assert result.ret == 0 |