Flake8 plugin that checks Pytest tests follow the Arrange Act Assert pattern
Project description
flake8-aaa plugin
A flake8 plugin for linting Python tests against the rules of the Arrange Act Assert pattern of testing.
Resources
Docs
(to be extracted to RTD)
Test discovery
Filename must start with test_ and have been collected for linting by flake8.
Test must be a function where its name starts with test.
Tests that contain only comments, docstrings or pass are skipped.
Error codes
AAA01: no Act block found in test
Test found to have no Act block.
An Act block is usually a line like result = or a check that an exception is raised using with pytest.raises(Exception):.
Resolution
Add an Act block to the test or mark a line that should be considered the action.
Even if the result of a test action is None, assign that result and test it:
result = action() assert result is None
If you can’t set a result, then mark the end of the line considered the Act block with # act (case insensitive):
data['new_key'] = 1 # act
AAA02: multiple Act blocks found in test
There must be one and only one Act block in every test. The linter found more than one potential Act block in this test.
A test that contains more than one result = statement or more than one line marked # act creates ambiguity and raises this error code.
Resolution
Splitting the failing test into multiple tests. Where there is complicated or reused set-up code then that should be extracted into fixtures.
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_aaa-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed327e389280ea8af90c6458929729f69013b58c54538dac988625e7187f61a7 |
|
MD5 | de336110d337679881b133577eed03b5 |
|
BLAKE2b-256 | 45ba9fa681757dfb0f2c65a01fad88da700d9428af15adbdcead12800f1cafad |