A collection of exercises for Pycon 2019 tutorial To trust or to test?: Automated testing of scientific projects with pytest
- You can find slides from the presentation here
- You can find full video from the PyCon 2019 conference here
Tutorial requires Python 3.6, Matplotlib 3.0, Scipy, Numpy, Pytest and Hypothesis. To create example animations you may need ffmpeg or mencoder packages.
This project now targets Python 3.9+. The dependencies have been consolidated into a single requirements.txt file for simplicity.
macOS
brew install ffmpeg
# Allure - optional (shown on github pages)
brew install allureWindows
choco install ffmpeg
# Allure - optional (shown on github pages)
scoop install alluremacOS
python3 -m venv venv
source venv/bin/activateWindows
python -m venv venv
.\venv\Scripts\activate.ps1- You should see (venv) in your terminal, indicating you are in the virtual environment.
pip install -r requirements.txt- With
pytest.ininow specifying the test path, you can simply run:
pytestThis will discover and run the tests automatically.
If you want more detailed output or need to see print/debug statements, you can use:
pytest -v -s-
-v: verbose mode -- shows each test's name and status -
-s: disables output capture =-- useful if you're usingprint()orpdb -
You can still specify the test path as an argument
pytest tests/allure/
macOS
pytest tests/ --alluredir allure-resultsWindows
pytest .\tests\ --alluredir allure-resultsGenerate a report
- You can also generate a visual report of this baseline using Allure
allure serve allure-results-
to install the tutorial example code:
$ pip install . -
to run the tutorial example code without installation:
$ python -m pycontest.simulation -
in case you have more than one python distribution you may need to specify python version to pytest:
$ python3 -m pytest tests