A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Project description
flake8-pytest-style
Description
A flake8
plugin checking common style issues or inconsistencies with pytest
-based tests.
Currently the following errors are reported:
-
PT001 use @pytest.fixture() over @pytest.fixture
The preferred style is controlled by the configuration optionpytest-fixture-no-parentheses
-
PT002 configuration for fixture '{name}' specified via positional args, use kwargs
e.g.@pytest.fixture(scope='module')
is OK, and@pytest.fixture('module')
is an error -
PT003 scope='function' is implied in @pytest.fixture()
e.g.@pytest.fixture(scope='function')
should be replaced with@pytest.fixture()
-
PT004 fixture '{name}' does not return anything, add leading underscore
-
PT005 fixture '{name}' returns a value, remove leading underscore
-
PT006 wrong name(s) type in @pytest.mark.parametrize, expected {expected_type}
e.g.@pytest.mark.parametrize(('name1', 'name2'), ...)
is ok, and@pytest.mark.parametrize('name1,name2', ...)
is an error -
PT007 wrong values type in @pytest.mark.parametrize, expected {expected_type}
-
PT008 use return_value= instead of patching with lambda
e.g.mocker.patch('target', return_value=7)
is OK, andmocker.patch('target', lambda *args: 7)
is an error -
PT009 use a regular assert instead of unittest-style '{assertion}'
-
PT010 set the expected exception in pytest.raises()
-
PT011 set the match parameter in pytest.raises({exception})
e.g.pytest.raises(ValueError, match='exception text')
is OK, andpytest.raises(ValueError)
is an error.
The exception list is controlled by the configuration optionpytest-raises-require-match-for
. -
PT012 pytest.raises() block should contain a single simple statement
this forbids multiple statements and control flow structures withinpytest.raises()
blocks. -
PT013 found incorrect import of pytest, use simple 'import pytest' instead
Installation
pip install flake8-pytest-style
Configuration
The plugin has the following configuration options:
-
pytest-fixture-no-parentheses
Boolean flag specifying whether@pytest.fixture()
without parameters should have parentheses, as checked byPT001
.
If the option is set to false (the default),@pytest.fixture()
is valid and@pytest.fixture
is an error.
If set to true,@pytest.fixture
is valid and@pytest.fixture()
is an error. -
pytest-raises-require-match-for
Comma-separated list of exception names that require amatch=
parameter in apytest.raises()
call, as checked byPT011
. By default the list contains the following exceptions:BaseException
,Exception
ValueError
OSError
,IOError
,EnvironmentError
,socket.error
For developers
Install deps and setup pre-commit hook
make init
Run linters, autoformat, tests etc.
make format lint test
Bump new version
make bump_major
make bump_minor
make bump_patch
License
MIT
Change Log
Unreleased
...
0.5.0 - 2020-03-09
- add configuration option
pytest-fixture-no-parentheses
forPT001
- add
PT013
(checks forfrom
-imports frompytest
)
0.4.0 - 2020-03-09
- add
PT012
(checks for multiple statements inwith pytest.raises()
)
0.3.1 - 2020-03-09
- fix default value of
pytest-raises-require-match-for
config option
0.3.0 - 2020-03-09
- add
PT010
andPT011
(checks forpytest.raises
parameters)
0.2.0 - 2020-03-01
- add
PT009
(ported from flake8-pytest)
0.1.3 - 2019-05-24
- add
yield
fixtures support - fix changelog entry for 0.1.2
0.1.2 - 2019-05-23
- fix parametrize checkers not working in decorators
0.1.1 - 2019-05-23
- update PyPI description
0.1.0 - 2019-05-23
- initial
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flake8-pytest-style-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ff18c8146c36050d1505f6f879c8a8baad8a39f6fe6a71267e5a0e148ba6ee |
|
MD5 | 1b16a75c5aa288e5e52002d28c9053da |
|
BLAKE2b-256 | d7eb3f5011525d1e2bfcda21c89c1f090570d41d3e6940e396404edc9e231bd0 |
Hashes for flake8_pytest_style-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c775f7286ac4727da0ae900fa800294e7500bbc220794e2b0043d9ef352f3145 |
|
MD5 | 5858ae287098f1c64636765150d4af6d |
|
BLAKE2b-256 | 4953451b073efe8cfdeaa1f8ce00c4131637331710ebaeed7d225dfbb32f02aa |