June's blog post: Arrange Act Assert guide#10
Conversation
|
TODO:
|
| I spoke about the Arrange Act Assert pattern and how it can help clean up unit | ||
| tests. I plan to write a short guide to AAA for Python developers and will | ||
| link to that from here when done - meanwhile, below are my slides and links | ||
| link to that from here when done - meanwhile, below is the video of the talk, my slides and links |
There was a problem hiding this comment.
This bad phrase will be removed when I link to the guide now.
|
|
||
| Thanks again to `Carles <https://github.com/txels>`_ for introducing me to the | ||
| AAA pattern. Check out his `data driven tests library | ||
| <https://github.com/txels/ddt>`_. |
There was a problem hiding this comment.
OOI, why remove the ref to ddt? Found other solutions like pytest.mark.parametrize 😉?
| :status: draft | ||
|
|
||
| This is the first post in a series exploring the Arrange Act Assert pattern and | ||
| how to apply it to Python unit tests. |
There was a problem hiding this comment.
maybe scrap the word 'unit'? It can be applied to functional tests too, etc.
|
|
||
| I'll now go into detail on each of these parts using Pytest and a simple toy | ||
| test example. We'll write a simple happy-path test for Python's builtin | ||
| ``list.reverse`` function. |
There was a problem hiding this comment.
You're mixing "I'll" / "We'll" in this paragraph, which sounds a bit confused
| * We all love `PEP008 <https://www.python.org/dev/peps/pep-0008/>`_, so we want | ||
| tests to pass ``flake8`` linting. | ||
|
|
||
| * `PEP020 <https://www.python.org/dev/peps/pep-0020/>`_ is also something we |
There was a problem hiding this comment.
I know this as the 'zen of python' instead of PEP 20, I had to click the link to remind myself that's what it is - maybe mention it as:
PEP020, The Zen of Python, is also something...
| Docstring | ||
| --------- | ||
|
|
||
| A short single line statement about the behaviour under test. |
There was a problem hiding this comment.
Personally I feel good test method names can make docstrings redundant in simple tests, and developers also find writing english harder than code 😉
There was a problem hiding this comment.
That's a helpful point. I've realised while considering this that the docstring is not really part of the pattern - it's my own addition. I'll rephrase to indicate that.
| will explore strategies for extracting common assertion code and testing it | ||
| in its own right. | ||
|
|
||
| Links will appear above when I complete these follow up posts. |
There was a problem hiding this comment.
Me too! I hope that I can keep up with the one post per month schedule! 😅
|
Thanks for the revew @adamchainz ... merging and publishing now. |
| Background | ||
| ---------- | ||
|
|
||
| I'll now go into detail on each of these parts using Pytest and a toy |
There was a problem hiding this comment.
Do you mean toy here or tox? Just checking.
There was a problem hiding this comment.
I definitely mean "toy". This is just a toy example where I write a test for something in stdlib.
Late, but 90% of the way there. Needs proof reading.
All suggestions welcome 😄