Skip to main content
AWX has a comprehensive test suite covering unit tests, functional tests, and integration tests. This guide covers how to run and write tests for AWX.

Test Framework

AWX uses pytest as its primary test framework. The pytest configuration is defined in pytest.ini at the repository root.

Pytest Configuration

Key settings from pytest.ini:

Running Tests

Basic Test Commands

From inside the AWX development container:

Using pytest Directly

Test Organization

Test Directory Structure

Test Types

Unit Tests: Test individual functions and classes in isolation
  • Location: awx/main/tests/unit/
  • Fast, isolated, use mocking
Functional Tests: Test API endpoints and workflows
  • Location: awx/main/tests/functional/
  • Integration-style tests with database
Collection Tests: Test the AWX Ansible collection
  • Location: awx_collection/test/awx/
  • Uses ansible-test framework

Writing Unit Tests

Basic Test Structure

Using Fixtures

Pytest fixtures provide reusable test data:

Using Markers

Markers categorize and filter tests:

Mocking

Use unittest.mock for isolating dependencies:

Functional Tests

API Testing

Functional tests often test API endpoints:

Collection Tests

AWX Collection Testing

The AWX Ansible collection has its own test suite:

Collection Test Structure

Writing Collection Tests

Code Coverage

Generating Coverage Reports

Coverage Configuration

.coveragerc file configures coverage settings:

Testing Best Practices

1. Test Isolation

Each test should be independent:

2. Use Fixtures for Setup

3. Test Edge Cases

4. Clear Test Names

5. Mock External Dependencies

Running Tests in CI

AWX uses GitHub Actions for continuous integration.

Local CI Testing

Run the same checks that CI runs:

Debugging Tests

Using pdb

Verbose Output

Capture Logs

Database Testing

Pytest automatically manages test databases:

Database Reuse

The --reuse-db flag (in pytest.ini) speeds up test runs by reusing the test database between runs.

Performance Testing

Test Execution Time

Profiling Tests

Next Steps