The rules applied by Flake8-AAA are from the Arrange Act Assert pattern for Python developers.
Note
The rules applied by Flake8-AAA are only a subset of the rules and guidelines of the Arrange Act Assert pattern itself. Please see the published guidelines for the pattern and read these rules in the context of the definition there.
Note
Flake8-AAA works best with the following Flake8 rules enabled:
E303
"too many blank lines"E702
"Multiple statements on one line"
An Act block is usually a line like result =
or a check that an exception is raised. Flake8-AAA could not find an Act block in the indicated test function.
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 pin it with a test:
result = action()
assert result is None
If you can not assign a result
, then mark the end of the line considered the Act block with # act
(case insensitive):
data['new_key'] = 1 # act
Code blocks wrapped in pytest.raises()
and unittest.assertRaises()
context managers are recognised as Act blocks.
There must be one and only one Act block in every test but Flake8-AAA found more than one potential Act block. This error is usually triggered when a test contains more than one result =
statement or more than one line marked # act
. Multiple Act blocks create ambiguity and raise this error code.
Split the failing test into multiple tests. Where there is complicated or reused set-up code then apply the DRY principle and extract the reused code into one or more fixtures.
For tests that have an Arrange block, there must be a blank line between the Arrange and Act blocks, but Flake8-AAA could not find one.
This blank line creates separation between the arrangement and the action and makes the Act block easy to spot.
This rule works best with pycodestyle's E303
rule enabled because it ensures that there are not multiple blank lines between the blocks.
Add a blank line before the Act block.
For tests that have an Assert block, there must be a blank line between the Act and Assert blocks, but Flake8-AAA could not find one.
This blank line creates separation between the action and the assertions and makes the Act block easy to spot.
As with rule AAA03
, this rule works best with E303
enabled.
Add a blank line before the Assert block.
The only blank lines in the test must be around the Act block making it easy to spot. Flake8-AAA found additional blank lines which break up the block's layout.
Remove the blank line.
This is an error code that is raised when Flake8 tries to mark a single line as occupied by two different types of block. It should never happen. The values for NEW_CODE
and OLD_CODE
are from the list of line-markers
.
Please open a new issue containing the output for the failing test as generated by the command-line
tool.
You could hack around with your test to see if you can get it to work while waiting for someone to reply to your issue. If you're able to adjust the test to get it to work, that updated test would also be helpful for debugging.