This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
forked from reverbc/pylint-pytest
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rules for pytest fixtures: (reverbc#17)
* Added rules to pytest fixtures: - rule for deprecated fixture scope as positional argument - rule for useless pytest.mark.usefixtures for fixtures - added tests for these checks * added to readme * Fixed comment in PR: - used check for all `@pytest.mark.*` decorators - edited error message for warnning W6403 - added py39 for testing
- Loading branch information
Showing
14 changed files
with
246 additions
and
2 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
6 changes: 6 additions & 0 deletions
6
tests/input/deprecated-positional-argument-for-pytest-fixture/with_args_scope.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,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture('function') | ||
def some_fixture(): | ||
return 'ok' |
6 changes: 6 additions & 0 deletions
6
tests/input/deprecated-positional-argument-for-pytest-fixture/with_kwargs_scope.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,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def some_fixture(): | ||
return 'ok' |
6 changes: 6 additions & 0 deletions
6
tests/input/deprecated-positional-argument-for-pytest-fixture/without_scope.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,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def some_fixture(): | ||
return 'ok' |
16 changes: 16 additions & 0 deletions
16
tests/input/useless-pytest-mark-decorator/mark_usefixture_using_for_class.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,16 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def first(): | ||
return "OK" | ||
|
||
|
||
@pytest.mark.usefixtures("first") | ||
class TestFirst: | ||
@staticmethod | ||
def do(): | ||
return True | ||
|
||
def test_first(self): | ||
assert self.do() is True |
18 changes: 18 additions & 0 deletions
18
tests/input/useless-pytest-mark-decorator/mark_usefixture_using_for_fixture_attribute.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,18 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def first(): | ||
return "OK" | ||
|
||
|
||
@pytest.fixture | ||
@pytest.mark.usefixtures("first") | ||
def second(): | ||
return "NOK" | ||
|
||
|
||
@pytest.mark.usefixtures("first") | ||
@pytest.fixture | ||
def third(): | ||
return "NOK" |
18 changes: 18 additions & 0 deletions
18
tests/input/useless-pytest-mark-decorator/mark_usefixture_using_for_fixture_function.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,18 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def first(): | ||
return "OK" | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
@pytest.mark.usefixtures("first") | ||
def second(): | ||
return "NOK" | ||
|
||
|
||
@pytest.mark.usefixtures("first") | ||
@pytest.fixture(scope="function") | ||
def third(): | ||
return "NOK" |
11 changes: 11 additions & 0 deletions
11
tests/input/useless-pytest-mark-decorator/mark_usefixture_using_for_test.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,11 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def first(): | ||
return "OK" | ||
|
||
|
||
@pytest.mark.usefixtures("first") | ||
def test_first(): | ||
pass |
26 changes: 26 additions & 0 deletions
26
tests/input/useless-pytest-mark-decorator/other_marks_using_for_fixture.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,26 @@ | ||
import os | ||
import pytest | ||
|
||
|
||
@pytest.mark.trylast | ||
@pytest.fixture | ||
def fixture(): | ||
return "Not ok" | ||
|
||
|
||
@pytest.mark.parametrize("id", range(2)) | ||
@pytest.fixture | ||
def fixture_with_params(id): | ||
return "{} not OK".format(id) | ||
|
||
|
||
@pytest.mark.custom_mark | ||
@pytest.fixture | ||
def fixture_with_custom_mark(): | ||
return "NOT OK" | ||
|
||
|
||
@pytest.mark.skipif(os.getenv("xXx")) | ||
@pytest.fixture | ||
def fixture_with_conditional_mark(): | ||
return "NOK" |
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 @@ | ||
from base_tester import BasePytestTester | ||
from pylint_pytest.checkers.fixture import FixtureChecker | ||
|
||
|
||
class TestDeprecatedPytestFixtureScopeAsPositionalParam(BasePytestTester): | ||
CHECKER_CLASS = FixtureChecker | ||
MSG_ID = 'deprecated-positional-argument-for-pytest-fixture' | ||
|
||
def test_with_args_scope(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(1) | ||
|
||
def test_with_kwargs_scope(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(0) | ||
|
||
def test_without_scope(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(0) |
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 @@ | ||
from base_tester import BasePytestTester | ||
from pylint_pytest.checkers.fixture import FixtureChecker | ||
|
||
|
||
class TestPytestMarkUsefixtures(BasePytestTester): | ||
CHECKER_CLASS = FixtureChecker | ||
MSG_ID = 'useless-pytest-mark-decorator' | ||
|
||
def test_mark_usefixture_using_for_test(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(0) | ||
|
||
def test_mark_usefixture_using_for_class(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(0) | ||
|
||
def test_mark_usefixture_using_for_fixture_attribute(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(2) | ||
|
||
def test_mark_usefixture_using_for_fixture_function(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(2) | ||
|
||
def test_other_marks_using_for_fixture(self): | ||
self.run_linter(enable_plugin=True) | ||
self.verify_messages(4) |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[tox] | ||
envlist = py27,py35,py36,py37,py38 | ||
envlist = py36,py37,py38,py39 | ||
skipsdist = True | ||
|
||
[testenv] | ||
|