Although the Python standard library comes with a unit testing framework called ùnittest, pytest is the go-to testing framework for testing Python code.
https://docs.pytest.org/en/latest/
Let's see how to use it
https://docs.pytest.org/en/latest/
Let's see how to use it
![Rückhand Zeigefinger nach unten 👇](https://abs.twimg.com/emoji/v2/72x72/1f447.png)
![Tastenkappe Ziffer 1 1️⃣](https://abs.twimg.com/emoji/v2/72x72/31-20e3.png)
1. Install it via pip - "pip install pytest"
2. Creta a new file "simple_test.py" containing code from the image
3. Run it - "pytest simple_test.py"
![Tastenkappe Ziffer 2 2️⃣](https://abs.twimg.com/emoji/v2/72x72/32-20e3.png)
It makes sense to use that when you want to wrap the test setup or complex assertions inside methods to make tests more readable
![Tastenkappe Ziffer 3 3️⃣](https://abs.twimg.com/emoji/v2/72x72/33-20e3.png)
pytest.ini - configuration for pytest
http://conftest.py - contains fixtures
tests - contains all tests
sum - package with production code (there can be multiple ones)
![Tastenkappe Ziffer 4 4️⃣](https://abs.twimg.com/emoji/v2/72x72/34-20e3.png)
They are so great that they have their own thread: https://twitter.com/jangiacomelli/status/1343849489379909633?s=20
![Tastenkappe Ziffer 5 5️⃣](https://abs.twimg.com/emoji/v2/72x72/35-20e3.png)
- pattern for searching test files
- pytest markers
- settings for plugins
![Tastenkappe Ziffer 6 6️⃣](https://abs.twimg.com/emoji/v2/72x72/36-20e3.png)
- pytest.mark.parametrize decorator
The same test will run for multiple different inputs
![Tastenkappe Ziffer 7 7️⃣](https://abs.twimg.com/emoji/v2/72x72/37-20e3.png)
- pytest-django - provides a set of tools made specifically for testing Django applications
- pytest-xdist - is used to run tests in parallel
- pytest-cov - adds code coverage support
![Tastenkappe Ziffer 8 8️⃣](https://abs.twimg.com/emoji/v2/72x72/38-20e3.png)
--ignore=some_folder
It can be used multiple times to exclude multiple folders.
![Tastenkappe Ziffer 9 9️⃣](https://abs.twimg.com/emoji/v2/72x72/39-20e3.png)