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
Copy file name to clipboardExpand all lines: 05_testing_and_ci/python_testing_demo.md
+3-18Lines changed: 3 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,7 @@ Example code is in [05_testing_and_ci/examples/python_testing](https://github.co
15
15
16
16
## pytest
17
17
18
-
- pytest is installed by:
19
-
20
-
```bash
21
-
pip install -U pytest
22
-
```
23
-
18
+
- pytest is installed using pip: `pip install pytest`.
24
19
- All tests can be run using the command-line tool called `pytest`. Just type `pytest` in the working directory and hit ENTER.
25
20
- If pytest is installed in some other way, you might need to run it like `python -m pytest`.
26
21
- One test is expected to fail. Reading the error message we understand that the failure occurs because floating-point variable comparison is not handled correctly.
@@ -80,12 +75,7 @@ tests/
80
75
- Base class `unittest.TestCase` is used to create a test suite.
81
76
- Each test is now a function of a class which is derived from the class `unittest.TestCase`.
82
77
- The same tests as for `pytest` are implemented using `unittest` in the file `test_operations_unittests.py`. The tests are functions of a class named `TestOperations` which tests our mathematical operations. The class `TestOperations` is derived from `unittest.TestCase`.
83
-
- unittest can be run as a Python module:
84
-
85
-
```bash
86
-
python -m unittest
87
-
```
88
-
78
+
- unittest can be run as a Python module: `python -m unittest`.
89
79
- unittest.TestCase offers functions like `assertEqual`, `assertAlmostEqual`, `assertTrue`, and more ([see unittest.TestCase documentation](https://docs.python.org/3/library/unittest.html#unittest.TestCase)) for use instead of the usual assertion statements. These statements ensure that test runner to accumulate all test results and generate a test report.
90
80
-`unittest.main()` provides an option to run the tests from a command-line interface and also from a file.
91
81
-`setUp` function is executed before all the tests. Similar a clean up function `tearDown` exists.
@@ -95,12 +85,7 @@ python -m unittest
95
85
96
86
## coverage
97
87
98
-
- Installing coverage using pip:
99
-
100
-
```bash
101
-
pip install -U coverage
102
-
```
103
-
88
+
- Installing coverage using pip: `pip install coverage`.
104
89
- Testing frameworks can be run via coverage. Lets take our first example and run pytest via coverage:
0 commit comments