https://pragprog.com/titles/bopytest2/python-testing-with-pytest-second-edition/
Create a virtual environment, activate it on POSIX systems, and install pytest
$ python3 -m venv venv_name
$ source venv_name/bin/activate
(venv_name) $ pip install pytest
or using virtualenv
$ python3 -m pip install virtualenv
$ python3 -m virtualenv venv_name
$ source venv_name/bin/activate
(venv_name) $ pip install pytest
Deactivate the venv
(venv_name) $ deactivate
Create a virtual environment, activate it on Windows systems, and install pytest
C:\> python -m venv venv_name
C:\> venv_name\Scripts\activate.bat
(venv_name) C:\> pip install pytest
Activate in PowerShell
C:>venv_name\Scripts\Activate.ps1
Run pytest
in the terminal:
$ pytest test_example-01-1--passing.py
===================================================================================================== test session starts ======================================================================================================
###
collected 1 item
test_example-01-1--passing.py . [100%]
====================================================================================================== 1 passed in 0.00s =======================================================================================================
$ pytest -v test_example-01-1--passing.py
===================================================================================================== test session starts ======================================================================================================
###
collected 1 item
test_example-01-1--passing.py::test_passing PASSED [100%]
====================================================================================================== 1 passed in 0.00s =======================================================================================================
Run all tests starting with test_
or ending with _test
in the current working directory without traceback
$ pytest --tb=no
Run tests given by their names or (sub)directories in which they are located
$ pytest --tb=no test_example-01-1--passing.py test_example-01-2--failing.py
$ cd ..
$ pytest --tb=no test_examples-01
Run only specified functions
$ cd test_examples-01
$ pytest -v test_example-01-1--passing.py::test_passing
test_<something>.py
or<something>_test.py
for filestest_<something>
for methods and functionsTest<Something>
for classes
https://pragprog.com/titles/bopytest2/source_code
https://doc.pytest.org/en/latest/example/reportingdemo.html
https://docs.pytest.org/en/latest/how-to/assert.html#assertion-introspection-details
https://docs.pytest.org/en/latest/reference/reference.html#exceptioninfo
https://xp123.com/3a-arrange-act-assert/
https://en.wikipedia.org/wiki/Test-driven_development
https://dannorth.net/introducing-bdd/
https://docs.python.org/3/library/pathlib.html#basic-use
https://docs.pytest.org/en/latest/reference/fixtures.html
https://docs.pytest.org/en/latest/reference/reference.html#metafunc