A short course on the basics of software testing in Python using the pytest library.
This lesson uses The Carpentries Workbench template.
It is derived from the FAIR2 for Research Software training course python-testing-for-research by the University of Sheffield.
Whether you are a seasoned developer or just write the occasional script, it's important to know that your code does what you intend, and will continue to do so as you make changes.
Software testing is a methodology of automatically ensuring that your code works correctly, without having to go back and manually verify after each change.
This course seeks to provide you with conceptual understanding and the tools you need to start ensuring the robustness of your code.
- Basic tests
- Running a test suite & understanding outputs
- Best practices
- Testing for errors
- Testing floating point data
- Fixtures
- Parametrisation
- Testing file outputs
- Continuous integration & automatic test-running with GitHub
Contributions are welcome, please refer to the contribution guidelines of how to do so and ensure that you adhere to the Code of Conduct.
To render the lesson locally, you will need to have R installed.
Instructions for using R with the Carpentries template is available on the
Carpentries website.
We recommend using the
{renv} package.
After cloning the repository, you can set up renv and install all packages with:
renv::init()
# Optionally update packages
renv::update()Once you have installed the dependencies, you can render the pages locally by starting R in the project root and running:
sandpaper::serve()When building the site subsequently, you may need to run renv::activate() first.
This will build the pages and start a local web-server in R and open it in your browser. These pages are "live" and will respond to local file changes if you save them.