"""Shared fixtures and configuration for integration tests."""
import pytest
import os
def pytest_configure(config):
"""Configure pytest markers."""
config.addinivalue_line(
"markers", "skip_collection_tests: Skip collection-related tests"
)
config.addinivalue_line(
"markers", "skip_api_tests: Skip API-related tests"
)
config.addinivalue_line(
"markers", "requires_auth: Tests that require valid authentication"
)
def pytest_addoption(parser):
"""Add custom pytest options."""
parser.addoption(
"--skip-collection-tests",
action="store_true",
default=False,
help="Skip collection-related tests"
)
parser.addoption(
"--skip-api-tests",
action="store_true",
default=False,
help="Skip API-related tests"
)
parser.addoption(
"--api-id",
type=str,
default=None,
help="API ID for testing get_api_details"
)
parser.addoption(
"--collection-id",
type=str,
default=None,
help="Collection ID for testing get_collection_apis"
)
parser.addoption(
"--http-url",
type=str,
default="http://localhost:8000",
help="HTTP server URL (default: http://localhost:8000)"
)
def pytest_collection_modifyitems(config, items):
"""Modify test items based on command line options."""
if config.getoption("--skip-collection-tests"):
skip_collection = pytest.mark.skip(reason="Skipping collection tests")
for item in items:
if "collection" in item.name.lower() and "test_get_collection_apis_with_id" in item.name:
item.add_marker(skip_collection)
if config.getoption("--skip-api-tests"):
skip_api = pytest.mark.skip(reason="Skipping API tests")
for item in items:
if "api_details" in item.name.lower() or ("api_id" in item.name.lower() and "test_get_api_details_with_id" in item.name):
item.add_marker(skip_api)
@pytest.fixture(scope="session")
def api_token():
"""Get API token from environment."""
token = os.getenv("42C_TOKEN")
if not token:
pytest.skip("42C_TOKEN environment variable not set")
return token