pytestlisted
Install: claude install-skill aiskillstore/marketplace
# Pytest Testing Framework
Pytest is a mature Python testing framework that makes it easy to write small tests while scaling to support complex functional testing.
## Quick Start
### Basic Test Structure
```python
# test_example.py
def test_addition():
assert 2 + 2 == 4
def test_string_operations():
assert "hello".upper() == "HELLO"
assert "world" in "hello world"
```
### Running Tests
```bash
# Run all tests
uv run pytest
# Run with verbose output
uv run pytest -v
# Run specific test file
uv run pytest test_example.py
# Run specific test function
uv run pytest test_example.py::test_addition
```
## Common Patterns
### Fixtures
**Basic fixture definition:**
```python
import pytest
@pytest.fixture
def sample_data():
return {"name": "Alice", "age": 30}
def test_user_data(sample_data):
assert sample_data["name"] == "Alice"
assert sample_data["age"] == 30
```
**Fixture with setup and teardown:**
```python
@pytest.fixture
def database_connection():
# Setup
conn = create_database_connection()
yield conn
# Teardown
conn.close()
def test_database_query(database_connection):
result = database_connection.query("SELECT * FROM users")
assert len(result) > 0
```
**Fixture scopes:**
```python
@pytest.fixture(scope="function") # Default - created per test
def temp_file():
pass
@pytest.fixture(scope="module") # Created once per module
def module_resource():
pass
@pytest.fixture(scope="session") # Created