Testing¶
Popoto includes a pytest plugin that automatically isolates tests in a dedicated Redis DB. It is the recommended way to run a project's test suite against Popoto models without contaminating development or production data.
Pytest Plugin (auto-registered)¶
The popoto.pytest_plugin module is registered as a pytest11 entry point and loads automatically when Popoto is installed. No configuration is required.
What the plugin does:
- Switches all Redis operations to DB 15 (or a configured DB) for the test session.
- Runs
flushdb()before each test for a clean slate. - Resets the async Redis connection per test to avoid event-loop conflicts.
Configuration priority (highest to lowest):
POPOTO_TEST_DBenvironment variablepopoto_test_dbini option inpyproject.toml[tool.pytest.ini_options]- Default:
15
DB 0 is rejected to prevent accidental test runs against production data. Non-integer values produce a clear error message.
Disabling the plugin:
Manual Test Helpers¶
The popoto.testing module provides helpers for non-pytest test runners or manual use:
from popoto.testing import use_test_db, flush_test_db
use_test_db(db=15) # Switch to test DB
flush_test_db() # Clear the test DB
These are not needed when using the pytest plugin, which handles both automatically.