mirror of
https://github.com/quay/quay.git
synced 2026-01-26 06:21:37 +03:00
2.5 KiB
2.5 KiB
Testing Guide
Test Commands
# Single test file
TEST=true PYTHONPATH="." pytest path/to/test.py -v
# Single test function
TEST=true PYTHONPATH="." pytest path/to/test.py::TestClass::test_function -v
# With short traceback
TEST=true PYTHONPATH="." pytest path/to/test.py -v --tb=short
# Quiet output (just pass/fail)
TEST=true PYTHONPATH="." pytest path/to/test.py -q --tb=no
# Pattern matching
TEST=true PYTHONPATH="." pytest path/to/test.py -k "keyword" -v
Test Types
Unit Tests
make unit-test
- Located throughout codebase in
test/subdirectories - Use SQLite in-memory database
- Fast, isolated tests
Registry Tests
make registry-test
- Located in
test/registry/ - Test Docker/OCI registry protocol
- Simulate Docker client operations
Integration Tests
make integration-test
- Located in
test/integration/ - Require running services
E2E Tests (Frontend)
# Cypress (legacy)
cd web && npm run test:integration
# Playwright (new)
cd web && npm run test:e2e
Test Database
Tests use SQLite by default. For PostgreSQL tests:
make test_postgres TESTS=test/test_file.py
Test Fixtures
Common Test Users
Defined in test/testconfig.py and used throughout tests:
devtable- Standard test userpublic- Public userreader- Read-only useradmin- Admin user
Test Repositories
devtable/simple- Basic test repopublic/publicrepo- Public repositorybuynlarge/orgrepo- Organization repository
Writing Tests
API Tests
import pytest
from test.fixtures import *
class TestMyFeature:
def test_example(self, app, initialized_db):
with client_with_identity('devtable', app) as cl:
result = cl.get('/api/v1/endpoint')
assert result.status_code == 200
Database Tests
from data.model import user
def test_user_creation(initialized_db):
new_user = user.create_user('testuser', 'password', 'test@example.com')
assert new_user.username == 'testuser'
Test Configuration
conftest.pyfiles contain pytest fixturestest/testconfig.py- Test user/repo configurationtox.ini- Tox test environments
Key Test Directories
test/- Main test directoryendpoints/api/test/- API endpoint testsendpoints/v2/test/- Registry v2 testsdata/model/test/- Model testsauth/test/- Auth testsworkers/test/- Worker testsweb/cypress/- Frontend Cypress testsweb/playwright/- Frontend Playwright tests