[TIP] Feedback request: flake8-aaa
me at jamescooke.info
Fri Sep 14 07:21:33 PDT 2018
Hi Ben (and list),
> Thanks for writing a style checker for test code.
Thanks for the positive feedback :D
> > https://flake8-aaa.readthedocs.io/en/stable/rules.html
> That page doesn't make clear to me: What consititudes a valid block of
> each kind?
> For example:
> * Must the “Act block” be an assignment? Are other statements allowed?
> Are multiple statements allowed? What exactly will be *not* allowed as
> an Act block?
Thanks for checking out the rules page on RTD. My intention with this page is that it should serve only a record of the checks currently carried about by flake8-aaa with some help about how to failures can be fixed - it is not intended to be a description of the AAA pattern. Instead, the list should be read in the context of the outline on the AAA pattern for Python developers, just as pycodestyle's error codes list (https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes) should be read in the context of PEP8, etc.
So to start to answer your questions on Act, please see my original outline of the AAA pattern: https://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html#act
> Must the “Act block” be an assignment? Are other statements allowed?
As of version 0.4.0 of flake8-aaa, there are three options:
* assignment `result =`
* pytest exception raised `with pytest.raises(...)`
* unittest exception raised `self.assertRaises(...)`.
> Are multiple statements allowed?
I'm interested to see an example of a test that requires multiple statements as the action. If you could share one that would be helpful. In my experience where I've come across actions with multiple statements, either the first statements are really arrangement, or the latter statements are really assertion / result manipulation, or a combination of both.
> What exactly will be *not* allowed as an Act block?
The developer can put anything they want in a Act block if they put ` # act` at the end of the statement. I've created that functionality to serve a bit like `#noqa` and also to allow for work arounds while the plugin is in beta. Is there some type of statement you would like to see banned from Act blocks?
> * What exactly constitutes a valid Assert block? What styles of
> assertion are recognised (pytest, nose, standard library `unittest`,
> others)? What constitutes an invalid Assert block?
For context, there is the definition of Assert from the AAA pattern: https://jamescooke.info/arrange-act-assert-pattern-for-python-developers.html#assert
Right now all assertions are recognised because I've made the plugin super lazy - it counts **all** the code after the Act block as the Assert block. My plan once the outstanding issues with Act blocks are fixed (https://github.com/jamescooke/flake8-aaa/issues/) is to add a check that there are no unnecessary spaces in Assert blocks, then to check that an Assert block exists for Act blocks that have an assignment.
> I don't want to use GitHub, so I hope you'll be participating in this
> forum where you asked for feedback :-)
I'll do my best!
Finally, in case it's helpful, there are some unittest test examples to an `examples/good` folder of the project repo. The plugin is tested against these at test time to assert that it does not complain about anything there: https://github.com/jamescooke/flake8-aaa/tree/master/examples/good
Hope you find those answers helpful - let me know your thoughts.
More information about the testing-in-python