popoto.testing¶
popoto.testing
¶
Testing utilities for Popoto.
Provides helpers for test isolation when running tests against Redis.
Automatic Plugin (Recommended):
If you install popoto and use pytest, the ``popoto.pytest_plugin`` is
registered automatically via entry points. It switches to a dedicated
test database (default: DB 15), flushes before each test, and resets
the async connection. No configuration needed -- just run ``pytest``.
To override the test DB number::
# Environment variable
POPOTO_TEST_DB=14 pytest
# Or in pyproject.toml
[tool.pytest.ini_options]
popoto_test_db = 14
To disable the plugin::
pytest -p no:popoto
Manual Helpers (for non-pytest or custom setups):
The functions below are available for test runners other than pytest
or for cases where you need manual control over DB switching::
# conftest.py
import pytest
from popoto.testing import use_test_db, flush_test_db
@pytest.fixture(scope="session", autouse=True)
def setup_test_db():
use_test_db(15)
yield
flush_test_db()
@pytest.fixture(autouse=True)
def clean_db():
yield
flush_test_db()
use_test_db(db=15)
¶
Switch to a test database for isolated testing.
Call this in your test setup to use a separate Redis database that won't interfere with development/production data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
int
|
Redis database number (0-15). Default is 15. |
15
|
Example
from popoto.testing import use_test_db
def setup_module(): use_test_db(15)
Source code in src/popoto/testing.py
flush_test_db()
¶
Flush the current database.
Use this in test teardown to clean up test data. WARNING: This deletes ALL keys in the current database.
Example
from popoto.testing import flush_test_db
def teardown_module(): flush_test_db()