This document explains how to run tests for the cepces project.
The project uses pytest for running tests. All tests have been migrated from unittest to pytest style.
The recommended way to run tests is using tox, which tests against multiple Python versions:
# Run tests for all configured Python versions
tox
# Run tests for a specific Python version
tox -e 3.11
tox -e 3.12
tox -e 3.13Run linting:
tox -e lintRun formatting checks:
tox -e formatRun type checking:
tox -e typeRun all tests using pytest:
pytest tests/Run tests with verbose output:
pytest tests/ -vRun a specific test file:
pytest tests/cepces_test/keyctl.py -vRun a specific test function:
pytest tests/cepces_test/keyctl.py::test_keyctl_handler_initialization_with_keyctl_available -vTest configuration is in pyproject.toml under the [tool.pytest.ini_options] section.
Default pytest options include:
-v: Verbose output--strict-markers: Strict marker checking--tb=short: Short traceback format
Tests are organized in the tests/cepces_test/ directory:
tests/
├── cepces_test/
│ ├── certmonger/ # Certmonger operation tests
│ ├── keyctl.py # Keyctl handler tests
│ ├── xcep/ # XCEP converter tests
│ └── xml/ # XML-related tests
All test functions must start with test_:
def test_my_feature():
assert Truepytest fixtures can be used for test setup:
import pytest
@pytest.fixture
def my_fixture():
return "test_data"
def test_with_fixture(my_fixture):
assert my_fixture == "test_data"Use pytest.raises() to test exceptions:
import pytest
def test_exception():
with pytest.raises(ValueError):
raise ValueError("error message")The project uses unittest.mock for mocking:
from unittest.mock import patch
@patch("module.function")
def test_with_mock(mock_function):
mock_function.return_value = "mocked"
assert module.function() == "mocked"Tests are automatically run on GitHub Actions for multiple Python versions (3.10-3.14).