Open mawaliya opened 1 year ago
I don't think this is a tool compatibility issue.
Consider a pytest file like:
import pytest
@pytest.mark.parametrize("param", ["one", "two", "three"])
def test_parameterized(param, snapshot):
assert param == snapshot
If you run pytest -k one
you get the correct output:
collected 3 items / 2 deselected / 1 selected
test_syrupy.py . [100%]
------------------------------------ snapshot report summary ------------------------------------
1 snapshot passed.
================================ 1 passed, 2 deselected in 0.02s ================================
But if you run pytest -k 'not one'
you get an error for unused snapshots:
collected 3 items / 1 deselected / 2 selected
test_syrupy.py .. [100%]
------------------------------------ snapshot report summary ------------------------------------
2 snapshots passed. 1 snapshot unused.
Re-run pytest with --snapshot-update to delete unused snapshots.
================================ 2 passed, 1 deselected in 0.02s ================================
EDIT: This is a completely separate issue related to syrupy's re-implementation of test selection with -k
.
Describe the bug
In the pytest using pytest_bdd. When we have several test using scenario outlines. When different scenario outlines have the same examples, then we run targeted test into only one example of a scenario outline using -k filter. Syrupy with JSONSnapshotExtension extension, will think other snapshots with same example from different scenario outlines are unused.
To reproduce
Have tests in bdd format like this: my_feature.feature
scenarios("my_feature.feature")
@pytest.fixture def custom_snapshot(snapshot: SnapshotAssertion): return snapshot.use_extension(JSONSnapshotExtension)
@then(parsers.cfparse("The result is {file_type}")) def check_the_file_type(file_type: str, custom_snapshot: SnapshotAssertion): assert file_type == custom_snapshot