forked from best-doctor/flake8-fine-pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from best-doctor/master
Adds unique tests names validator (best-doctor#7)
- Loading branch information
Showing
7 changed files
with
61 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,7 @@ venv.bak/ | |
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.mypy_cache/ | ||
|
||
# IDE | ||
.idea |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ast | ||
from typing import Set | ||
|
||
from flake8_fine_pytest.watchers.base import BaseWatcher | ||
|
||
|
||
class UniqueTestNamesWatcher(BaseWatcher): | ||
error_template = 'FP009 Duplicate name test case ({})' | ||
|
||
def run(self) -> None: | ||
testcases_names: Set[str] = set() | ||
|
||
if not self._is_test_file(self.filename): | ||
return | ||
|
||
for node in ast.walk(self.tree): | ||
if not self._should_check_node(node): | ||
continue | ||
|
||
node_name = node.name # type: ignore | ||
|
||
if node_name not in testcases_names: | ||
testcases_names.add(node_name) | ||
continue | ||
|
||
error_msg = self.error_template.format(node_name) | ||
self.add_error((node.lineno, 0, error_msg)) |
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,19 @@ | ||
import pytest | ||
|
||
|
||
def test_not_uniq(): | ||
pass | ||
|
||
|
||
def test_not_uniq(): | ||
pass | ||
|
||
|
||
@pytest.mark.skip | ||
def test_not_uniq_with_decorator(): | ||
pass | ||
|
||
|
||
@pytest.mark.skip | ||
def test_not_uniq_with_decorator(): | ||
pass |
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,6 @@ | ||
def test_unique_names(run_validator_for_test_files): | ||
errors = run_validator_for_test_files('test_not_unique.py') | ||
|
||
assert len(errors) == 2 | ||
assert errors[0][2] == 'FP009 Duplicate name test case (test_not_uniq)' | ||
assert errors[1][2] == 'FP009 Duplicate name test case (test_not_uniq_with_decorator)' |