This document explains how to run tests for the vex-reader project.
The project has been configured with a comprehensive testing setup that includes:
- Unit tests using Python's built-in
unittestframework - pytest support for advanced testing features
- Coverage reporting to track test coverage
- GitHub Actions for continuous integration
- Multiple Python version support (3.8 - 3.12)
tests/
├── __init__.py
├── test_vex1.py # Main test file
├── cve-2024-21626.json # Test data
├── cve-2024-40951.json # Test data
└── cisco-sa-openssh-rce-2024.json # Test data
The easiest way to run tests is using the provided test runner script:
# Run tests with unittest (default)
python run_tests.py --verbose
# Run tests with unittest only
python run_tests.py --unittest --verbose
# Run tests with pytest and coverage
python run_tests.py --pytest --coverage --verbose
# Install dependencies and run tests
python run_tests.py --install-deps --verbose# Show available targets
make help
# Run basic tests
make test
# Install development dependencies
make install-dev
# Run tests with coverage (requires pytest)
make test-cov
# Run linting checks
make lint
# Clean build artifacts
make clean
# Build the package
make build# Using unittest (no additional dependencies required)
python -m unittest discover tests -v
# Using pytest (requires pytest installation)
python -m pytest tests/ -v
# Using pytest with coverage
python -m pytest tests/ --cov=vex --cov-report=term-missing --cov-report=htmlTo install the optional test dependencies:
# Install test dependencies
pip install -e .[test]
# Or install specific packages
pip install pytest pytest-cov pytest-xdistThe project is configured to generate coverage reports:
- Terminal output: Shows coverage percentage per file
- HTML report: Generates detailed coverage report in
htmlcov/directory
# Generate coverage report
python -m pytest tests/ --cov=vex --cov-report=html
# Open htmlcov/index.html in your browserThe project uses GitHub Actions for continuous integration:
- Multiple Python versions: Tests run on Python 3.8, 3.9, 3.10, 3.11, and 3.12
- Automatic testing: Tests run on every push and pull request
- Code quality checks: Includes linting and security scanning
- Build verification: Ensures the package builds correctly
The CI workflow includes:
- Test job: Runs tests on multiple Python versions
- Lint job: Checks code quality with flake8, black, and isort
- Security job: Scans for security vulnerabilities
- Build job: Builds and validates the package
The tests use real VEX (Vulnerability Exchange) files as test data:
cve-2024-21626.json: Contains CVSS data and vulnerability informationcve-2024-40951.json: Contains vulnerability data without CVSS scorescisco-sa-openssh-rce-2024.json: Cisco security advisory format
When adding new tests:
- Follow the existing test structure in
tests/test_vex1.py - Use descriptive test method names starting with
test_ - Include test data files in the
tests/directory - Use proper assertions and error handling
- Test both success and failure cases
Example test structure:
import os
import sys
from unittest import TestCase
# Add the parent directory to the path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from vex import Vex, VexPackages
class TestNewFeature(TestCase):
def setUp(self):
test_file = os.path.join(os.path.dirname(__file__), 'test-data.json')
self.vex = Vex(test_file)
def test_feature_functionality(self):
# Test implementation here
self.assertEqual(self.vex.some_property, 'expected_value')- Import errors: Make sure the vex module is properly installed
- File not found: Check that test data files exist in the tests directory
- Permission errors: Ensure you have read permissions for test files
- Python version: Some features may require specific Python versions
If you encounter issues:
- Check the GitHub Actions logs for CI failures
- Run tests locally with verbose output
- Verify all dependencies are installed
- Check that test data files are present and accessible
- Run tests before committing: Always run tests locally before pushing
- Keep tests fast: Unit tests should run quickly
- Test edge cases: Include tests for error conditions and edge cases
- Maintain test data: Keep test data files up to date
- Document changes: Update this guide when adding new testing features