Skip to content

Commit cd38087

Browse files
committed
Reformat decorator aside and fix clunky wording
1 parent 9157db1 commit cd38087

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Python/Module6_Testing/Pytest.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ jupyter:
1818
:keywords: test, automated, pytest, parametrize, fixture, suite, decorator, clean directory
1919
<!-- #endraw -->
2020

21-
# The pytest Framework
21+
# Designing a Test Suite for a Python Project
2222

23-
Thus far, our process for running tests has been an entirely manual one. It is time for us to arrange our test functions into a proper "test suite" and to learn to leverage [the pytest framework](https://docs.pytest.org/en/latest/) to run them.
23+
Thus far, our process for running tests has been an entirely manual one – we have been responsible for running each test-function and noting whether or not an assertion error was raised.
24+
It is time for us to arrange our test functions into a proper "test suite" and to learn to leverage [the pytest framework](https://docs.pytest.org/en/latest/) to run them.
25+
This will make it trivial for us to run all (or a subset) of our tests with a single command and to view the pass/fail status of each test in a nice list.
2426
We will begin by reorganizing our source code to create an installable [Python package](https://www.pythonlikeyoumeanit.com/Module5_OddsAndEnds/Modules_and_Packages.html#Packages).
2527
We will then learn how to structure and run a test suite for this Python package, using pytest.
2628

@@ -69,8 +71,8 @@ While [unittest.mock](https://docs.python.org/3/library/unittest.mock.html) prov
6971
There is a project, "Nose2", which is carrying the torch of `nose`. However, this is a fledgling project in comparison with `pytest`.
7072
As of writing this, `pytest` was downloaded 12 million times last month versus `nose2`'s 150 thousand downloads.
7173

72-
The takeaway here is that, when it comes to picking a testing framework for Python, `pytest` is the clear choice.
73-
Any discussion that you come across to the contrary is likely outdated.
74+
The takeaway here is that `pytest` is the clear choice when it comes to picking a testing framework for Python.
75+
Any discussion that you come across to the contrary is likely outdated or is lending too much legitimacy to out-dated frameworks.
7476
</div>
7577

7678
<!-- #region -->
@@ -418,10 +420,13 @@ Furthermore, the four assertions are now being run independently from one anothe
418420
<!-- #endregion -->
419421

420422
<!-- #region -->
421-
#### Decorators
423+
424+
<div class="alert alert-warning">
425+
426+
**Decorators**
422427

423428
The syntax used to parameterize this test may look alien to us, as we have yet to encounter this construct thus far.
424-
`pytest.mark.parameterize(...)` is a _decorator_ - an object that is used to "wrap" a function in order to transform its behavior.
429+
`pytest.mark.parameterize(...)` is a _decorator_ an object that is used to "wrap" a function in order to transform its behavior.
425430
The `pytest.mark.parameterize(...)` decorator wraps our test function so that pytest can call it multiple times, once for each parameter value.
426431
The `@` character, in this context, denotes the application of a decorator:
427432

@@ -434,6 +439,9 @@ def the_function_being_decorated(<arguments_for_function>):
434439
```
435440

436441
For an in-depth discussion of decorators, please refer to [Real Python's Primer on decorators](https://realpython.com/primer-on-python-decorators/#simple-decorators).
442+
</div>
443+
444+
437445
<!-- #endregion -->
438446

439447
<!-- #region -->

0 commit comments

Comments
 (0)