Summary and Schedule
This is a new lesson built with The Carpentries Workbench.
Setup Instructions | Download files required for the lesson | |
Duration: 00h 00m | 1. Introduction | What are the goals of this course? |
Duration: 00h 12m | 2. Why Test My Code? | Why should I test my code? |
Duration: 00h 24m | 3. Simple Tests |
How to write a simple test? How to run the test? |
Duration: 00h 36m | 4. Interacting with Tests |
How do I use pytest to run my tests? What does the output of pytest look like and how do I interpret it? |
Duration: 00h 48m | 5. Unit tests & Testing Practices |
What to do about complex functions & tests? What are some testing best practices for testing? How far should I go with testing? How do I add tests to an existing project? |
Duration: 01h 00m | 6. Testing for Exceptions | How check that a function raises an exception? |
Duration: 01h 12m | 7. Testing Data Structures |
How do you compare data structures such as lists and
dictionaries? How do you compare objects in libraries like pandas and numpy ?
|
Duration: 01h 24m | 8. Fixtures | How to reuse data and objects in tests? |
Duration: 01h 36m | 9. Parametrization | Is there a better way to test a function with lots of different inputs than writing a separate test for each one? |
Duration: 01h 48m | 10. Regression Testing and Plots |
How to test for changes in program outputs? How to test for changes in plots? |
Duration: 02h 00m | 11. Continuous Integration with GitHub Actions |
How can I automate the testing of my code? What are GitHub Actions? |
Duration: 02h 12m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Python testing for research
This course aims to equip you with the tools and knowledge required to get started with software testing. It assumes no prior knowledge of testing, just basic familiarity with Python programming. Over the course of these lessons, you will learn what software testing entails, how to write tests, best practices, some more niche & powerful functionality and finally how to incorporate tests in a GitHub repository.
Software Setup
Please complete these setup instructions before the course starts. This is to ensure that the course can start on time and all of the content can be covered. If you have any issues with the setup instructions, please reach out to a course instructor / coordinator.
For this course, you will need:
A Terminal
Such as Terminal on MacOS / Linux or command prompt on Windows. This is so that you can run Python scripts and commit code to GitHub.
A Text Editor
Preferably a code editor like Visual Studio Code but any text editor will do, such as notepad. This is so that you can write and edit Python scripts. A code editor will provide a better experience for writing code in this course. We recommend Visual Studio Code as it is free and very popular with minimal setup required.
Python
Preferably Python 3.10 or 3.11. You can download Python from Python’s official website
It is recommended that you use a virtual environment for this course. This can be a standard Python virtual environment or a conda environment. You can create a virtual environment using the following commands:
BASH
# For a standard Python virtual environment
python -m venv myenv
source myenv/bin/activate
# For a conda environment
conda create --name myenv
conda activate myenv
There are some python packages that will be needed in this course, you can install them using the following command:
Git
This course touches on some features of GitHub and requires Git to be installed. You can download Git from the official Git website. If this is your first time using Git, you may want to check out the Git Handbook.
A GitHub account
A GitHub accound is required for the Continuous Integration section of this course. You can sign up for a GitHub account on the GitHub Website