Skip to content

Commit bb86c5d

Browse files
committed
update Python chapter testing section
Fixes NLeSC#220.
1 parent 22e1c8b commit bb86c5d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

best_practices/language_guides/python.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,15 @@ Autoformatting tools like [`yapf`](https://github.com/google/yapf) and [`black`]
127127

128128
## Testing
129129

130-
* [pytest](https://docs.pytest.org/) is a full featured Python
131-
testing tool. You can use it with `unittest`.
132-
[Pytest intro](http://pythontesting.net/framework/pytest/pytest-introduction/)
133-
* [Using mocks in Python](http://www.drdobbs.com/testing/using-mocks-in-python/240168251)
134-
* [unittest](https://docs.python.org/3/library/unittest.html) is a
135-
framework available in Python Standard Library.
136-
[Dr.Dobb's on Unit Testing with Python](http://www.drdobbs.com/testing/unit-testing-with-python/240165163)
137-
* [doctest](https://docs.python.org/3/library/doctest.html) searches for pieces of text that look like interactive Python sessions, and then executes those sessions to verify that they work exactly as shown. Always use this if you have example code in your documentation to make sure your examples actually work.
138-
139-
Using `pytest` is preferred over `unittest`, `pytest` has a much more concise syntax and supports many useful features.
140-
141-
Please make sure the command `python setup.py test` can be used to run your tests. When using `pytest`, this can be easily configured as described in the [`pytest` documentation](https://docs.pytest.org/en/latest/goodpractices.html#integrating-with-setuptools-python-setup-py-test-pytest-runner).
130+
Use [pytest](https://docs.pytest.org/) as the basis for your testing setup.
131+
This is preferred over the `unittest` standard library, because it has a much more concise syntax and supports many useful features.
132+
133+
It [has many plugins](https://docs.pytest.org/en/stable/plugins.html).
134+
For linting, we have found `pytest-pycodestyle`, `pytest-mypy` and `pytest-flake8` to be useful.
135+
Other plugins we had good experience with are `pytest-cov`, `pytest-html` and `pytest-xdist`.
136+
137+
Creating mocks can also be done within the pytest framework by using the `mocker` fixture provided by the `pytest-mock` plugin or by using `MagicMock` and `patch` from `unittest`.
138+
142139

143140
### Code coverage
144141

0 commit comments

Comments
 (0)