Repository: jamescooke/flake8-aaa

Issue:
Allow `pytest.raises` in assert blocks
In this test from here: https://github.com/constructpm/pysyncgateway/blob/master/tests/user/test_delete.py#L8-L14

```
def test(existing_user):
    result = existing_user.delete()

    assert result is True
    assert result.retrieved is False
    with pytest.raises(DoesNotExist):
        result.retrieve()
```

`flake8-aaa` raises `AAA02` multiple Act blocks found in test.

Instead, `flake8-aaa` should allow this because checking that results raise exceptions is part of a normal testing process.

Discussion:

Patch:
diff --git a/flake8_aaa/function.py b/flake8_aaa/function.py
index e353135..2944886 100644
--- a/flake8_aaa/function.py
+++ b/flake8_aaa/function.py
@@ -46,6 +46,12 @@ class Function:
             except NotActionBlock:
                 continue
 
+        # Allow `pytest.raises` in assert blocks
+        if len(self.act_blocks) > 1:
+            self.act_blocks = [self.act_blocks[0]] + list(
+                filter(lambda ab: ab.block_type != ActBlock.PYTEST_RAISES, self.act_blocks[1:])
+            )
+
         self.parsed = True
         return len(self.act_blocks)
 
diff --git a/setup.cfg b/setup.cfg
index dbb65e4..9211379 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -9,5 +9,6 @@ not_skip=__init__.py
 max-line-length = 120
 
 [yapf]
+# coalesce_brackets = true
 dedent_closing_brackets = true
 column_limit = 120
diff --git a/tox.ini b/tox.ini
index aa37fc8..ef19d36 100644
--- a/tox.ini
+++ b/tox.ini
@@ -13,4 +13,5 @@ commands =
     install: flake8 --version
     test: pytest
     lint: make lint
+setenv = IN_TOX = 1
 whitelist_externals = make


Test patch:
diff --git a/tests/function/test_check.py b/tests/function/test_check.py
index a95d8e1..8f13981 100644
--- a/tests/function/test_check.py
+++ b/tests/function/test_check.py
@@ -17,12 +17,25 @@ def test_noop(function):
     assert result == []
 
 
-@pytest.mark.parametrize('code_str', ['''
+@pytest.mark.parametrize(
+    'code_str', [
+        '''
 def test():
     result = 1
 
     assert result == 1
-'''])
+''',
+        '''
+def test(existing_user):
+    result = existing_user.delete()
+
+    assert result is True
+    assert result.retrieved is False
+    with pytest.raises(DoesNotExist):
+        result.retrieve()
+''',
+    ]
+)
 def test_result_assigned(function):
     function.parse()
 
@@ -51,7 +64,7 @@ def test():
     x = 1 + 1  # act
     assert x == 2
 '''])
-def test_no_qa(function):
+def test_act(function):
     function.parse()
 
     result = function.check()
diff --git a/tests/function/test_parse.py b/tests/function/test_parse.py
index 910d0cd..ecbf225 100644
--- a/tests/function/test_parse.py
+++ b/tests/function/test_parse.py
@@ -1,5 +1,7 @@
 import pytest
 
+from flake8_aaa.act_block import ActBlock
+
 
 @pytest.mark.parametrize('code_str', ['def test():\n    pass'])
 def test_none(function):
@@ -45,3 +47,25 @@ def test_multi(function):
     assert result == 2
     assert function.parsed is True
     assert function.is_noop is False
+
+
+@pytest.mark.parametrize(
+    'code_str', [
+        '''
+def test(existing_user):
+    result = existing_user.delete()
+
+    assert result is True
+    assert result.retrieved is False
+    with pytest.raises(DoesNotExist):
+        result.retrieve()
+'''
+    ]
+)
+def test(function):
+    result = function.parse()
+
+    assert result == 1
+    assert function.parsed is True
+    assert function.is_noop is False
+    assert function.act_blocks[0].block_type == ActBlock.RESULT_ASSIGNMENT
diff --git a/tests/test_run.py b/tests/test_run.py
index bb0b7a6..0550997 100644
--- a/tests/test_run.py
+++ b/tests/test_run.py
@@ -4,15 +4,23 @@
 
 # Some unicode text: Réne has £10 - ensure that this file is loaded with Python 2
 
+import os
+
+import pytest
+
 from flake8_aaa.__about__ import __version__
 
+skip_not_tox = pytest.mark.skipif(not os.getenv('IN_TOX', False), reason='Not running inside Tox')
+
 
+@skip_not_tox
 def test_installed(flake8dir):
     result = flake8dir.run_flake8(extra_args=['--version'])
 
     assert 'aaa: {}'.format(__version__) in result.out
 
 
+@skip_not_tox
 def test(flake8dir):
     flake8dir.make_py_files(
         test_plus='''