Aniworld/tests/conftest_api.py

50 lines
1.4 KiB
Python

"""
Pytest configuration for API tests.
"""
import pytest
import sys
import os
# Add necessary paths for imports
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src', 'server'))
@pytest.fixture(scope="session")
def api_test_config():
"""Configuration for API tests."""
return {
'base_url': 'http://localhost:5000',
'test_timeout': 30,
'mock_data': True
}
def pytest_configure(config):
"""Configure pytest with custom markers."""
config.addinivalue_line(
"markers", "api: mark test as API endpoint test"
)
config.addinivalue_line(
"markers", "auth: mark test as authentication test"
)
config.addinivalue_line(
"markers", "integration: mark test as integration test"
)
config.addinivalue_line(
"markers", "unit: mark test as unit test"
)
def pytest_collection_modifyitems(config, items):
"""Auto-mark tests based on their location."""
for item in items:
# Mark tests based on file path
if "test_api" in str(item.fspath):
item.add_marker(pytest.mark.api)
if "integration" in str(item.fspath):
item.add_marker(pytest.mark.integration)
elif "unit" in str(item.fspath):
item.add_marker(pytest.mark.unit)
if "auth" in item.name.lower():
item.add_marker(pytest.mark.auth)