- Every feature must have a test.
- Every bug must have a regression test.
- Bug fix workflow: FIRST write a test that expects proper behavior, verify it fails, THEN make the fix, and verify the test passes.
Tests require MongoDB and Redis. Start them if they aren't already running:
# Start MongoDB (if not already running)
docker ps | grep -q mongo || docker run -d --name bbot-mongo --ulimit nofile=64000:64000 --rm -p 127.0.0.1:27017:27017 mongo
# Start Redis (if not already running)
docker ps | grep -q redis || docker run -d --name bbot-redis --rm -p 127.0.0.1:6379:6379 redisThen run the tests:
# run all tests
uv run pytest -v
# run specific tests
uv run pytest -v -k test_applet_targets
# stop on first failure
uv run pytest -x- Tests use pytest with pytest-asyncio (
asyncio_mode = "auto"). - Tests live in
tests/. - Test database config is in
tests/test_config.yml(MongoDB:mongodb://localhost:27017/test_bbot, Redis:redis://localhost:6379/15). - Database cleanup fixtures (
mongo_cleanup,redis_cleanup) run before/after each test.
Features typically need both an API test and a CLI test:
- API test in
tests/test_applets/— verifies the feature works through the Python and HTTP interfaces. - CLI test in
tests/test_cli/— verifies the feature is accessible and correct viabbctlcommand-line flags.
- Unit/integration tests are async functions (
async def test_*) that use thebbot_serverfixture.- The
bbot_serverfixture is parametrized acrosspythonandhttpinterfaces. Call it asbbot_server = await bbot_server().
- The
- Applet lifecycle tests inherit from
tests.test_applets.base.BaseAppletTestand overridesetup(),after_scan_1(),after_scan_2(),after_archive(). Setneeds_worker = Trueif the test requires a worker. - Target models can be tested directly:
from bbot_server.modules.targets.targets_models import CreateTarget, Target.
- Use subprocess calls via
BBCTL_COMMANDand thebbot_server_httpfixture (see existing tests intests/test_cli/for the pattern). - Parse JSON output with
orjson.loads(process.stdout), check return codes and stderr messages.