You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
24
26
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).
25
27
We will then learn how to structure and run a test suite for this Python package, using pytest.
26
28
@@ -69,8 +71,8 @@ While [unittest.mock](https://docs.python.org/3/library/unittest.mock.html) prov
69
71
There is a project, "Nose2", which is carrying the torch of `nose`. However, this is a fledgling project in comparison with `pytest`.
70
72
As of writing this, `pytest` was downloaded 12 million times last month versus `nose2`'s 150 thousand downloads.
71
73
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.
74
76
</div>
75
77
76
78
<!-- #region -->
@@ -418,10 +420,13 @@ Furthermore, the four assertions are now being run independently from one anothe
418
420
<!--#endregion -->
419
421
420
422
<!--#region -->
421
-
#### Decorators
423
+
424
+
<div class="alert alert-warning">
425
+
426
+
**Decorators**
422
427
423
428
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.
425
430
The `pytest.mark.parameterize(...)` decorator wraps our test function so that pytest can call it multiple times, once for each parameter value.
426
431
The `@` character, in this context, denotes the application of a decorator:
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).
0 commit comments