An Act block can be overly complex when parent nodes of the Act node contain "extra" lines.
In a simple example, an Act node with a context manager ('pytest_raises' or 'unittest_raises' types) can wrap other nodes "below" it.
def test()
with pytest.raises(ValueError): # < Act node, Act block first line
do_thing()
do_other_thing() # < Act block last line
In this case do_other_thing() can be "smuggled" into the Act block because it's wrapped in the pytest.raises() context manager.
A more complex example, extra statements can be wrapped by context managers which are found that are parents of the Act node:
def test():
with mock.patch('thing.thinger') as mock_thinger: # < Act block first line
with mock.patch('other_thing.thinger'):
with pytest.raises(ValueError): # < Act node
do_thing()
do_other_thing2()
do_other_thing3() # < Act block last line
assert mock_thinger.call_count == 1
In this case, do_other_thing2() and do_other_thing3() are wrapped by the mock.patch() context managers and are then "smuggled" into the Act block.
Requirements
-
Add non-blocking rule for over-complex act block. Point error raised at the additional lines. Resolution is to move the additional lines outside of any act block, maybe to extract them to a fixture or setUp() function.
-
Checking of Act block should be wired in to happen after Act block is linted.
-
Add documentation and tests.
An Act block can be overly complex when parent nodes of the Act node contain "extra" lines.
In a simple example, an Act node with a context manager ('pytest_raises' or 'unittest_raises' types) can wrap other nodes "below" it.
In this case
do_other_thing()can be "smuggled" into the Act block because it's wrapped in thepytest.raises()context manager.A more complex example, extra statements can be wrapped by context managers which are found that are parents of the Act node:
In this case,
do_other_thing2()anddo_other_thing3()are wrapped by themock.patch()context managers and are then "smuggled" into the Act block.Requirements
Add non-blocking rule for over-complex act block. Point error raised at the additional lines. Resolution is to move the additional lines outside of any act block, maybe to extract them to a fixture or
setUp()function.Checking of Act block should be wired in to happen after Act block is linted.
Add documentation and tests.