Skip to content

SylviaWhittle/python-testing-for-research

Repository files navigation

Python testing for research

A short course on the basics of software testing in Python using the pytest library.

This lesson uses The Carpentries Workbench template.

Course Description

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.

Contents

  • Basic tests
  • Running a test suite & understanding outputs
  • Best practices
  • Testing for errors
  • Testing data structures
  • Fixtures
  • Parametrisation
  • Testing file outputs
  • Continuous integration & automatic test-running with GitHub

Contributions

Contributions are welcome, please refer to the contribution guidelines of how to do so and ensure that you adhere to the Code of Conduct.

Build the lesson locally

To render the lesson locally, you will need to have R installed. Instructions for using R with the Carpentries template is available but some additional setps have been taken to make sure the enivronment is reproducible using the {renv} package and an renv.lockfile is included which allows the environment to be re-created along with dependencies.

After cloning the repository, you can set up the renv and install all packages with:

renv::restore()
# 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()

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.