https://github.com/pybites/pytest-tips
https://github.com/pybites/pytest-tips
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pybites/pytest-tips
- Owner: pybites
- Created: 2024-06-11T17:34:11.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T17:45:52.000Z (12 months ago)
- Last Synced: 2025-03-28T05:23:38.016Z (2 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pytest Tips
This repository contains various examples and tips for using pytest effectively. Below are the included tips and corresponding examples.
## Contents
1. **Adding More Info to Your Tests**
- `test_objects.py`: Demonstrates using `pytest.param` to apply marks or set test IDs to individual parameterized tests.2. **Organizing Pytest Fixtures**
- `conftest.py`: Shows how to define fixtures in a `conftest.py` file for reusability across multiple test files.
- `test_pysource.py`: Contains tests that utilize the fixture defined in `conftest.py`.3. **Skipping Tests Based on Conditions**
- `test_comments.py`: Uses `pytest.mark.skipif` to conditionally skip tests if a module cannot be imported.4. **Debugging Hanging Tests**
- `hang.py`: Contains a function that simulates a long-running operation.
- `test_hang.py`: Demonstrates using `pytest.mark.timeout` and `pytest.mark.xfail` to handle and expect timeouts.5. **Detailed Setup/Teardown Info with `--setup-show`**
- `test_scope.py`: Shows how to use `--setup-show` to get detailed information about fixture setup and teardown, demonstrating both module and function scope.## Running the Tests
1. Install the dependencies (`pytest` and `pytest-timeout`):
```bash
pip install -r requirements-dev.txt
```2. Run all tests:
```bash
pytest
```3. For detailed setup/teardown information, run:
```bash
pytest test_scope.py --setup-show
```