This repository provides an interactive introduction to the pytest testing framework for Python.
The recommended way to install this repo is through git, which can be downloaded here. Once downloaded, execute the command:
git clone https://github.com/jstadni2/pytest-fundamentals
Next, download the appropriate Python installer for your machine. Make sure to add Python to PATH
.
Run one of the following commands according to your operating system to install pytest
.
macOS:
pip3 install -r requirements.txt
Windows (Powershell):
pip install -r requirements.txt
While not essential for using pytest
, this repo includes a demonstration of Visual Studio Code integration. The installer can be downloaded here. The Python extension for Visual Studio Code is required to run pytest
test suites using the GUI.
- A process of evaluating and verifying whether software meets specified requirements and functions correctly
- Detect bugs before they are encountered by users and ensure software is robust and performant
- Prevent refactoring or additional features from breaking preexisting functionality (regression)
- Unit Tests: test the smallest testable part of the software (eg. a function, method, or class)
- Integration Tests: test the interaction between different units or components
- End-to-End Tests: test the entire system in a real-world scenario
- As you move up the pyramid:
- Execution time typically increases
- Cost to implement/maintain increases
- Run time-consuming or repetitive tasks more efficiently
- Repeatable, consistent, and cost-effective
- Allows for more comprehensive testing of edge cases
- Can be integrated into Continuous Integration and Continuous Delivery pipelines (CI/CD)
- Setup: Initialize data and create the preconditions needed to test specific functionality
- Act: Execute the function or system under test
- Assert: Compare the output or behavior of the software with the expected results
- Cleanup: Tear down test resources or revert state changes to prepare for subsequent tests