BaseTest Class
TheBaseTest class provides a base implementation for end-to-end testing of workflows. It includes several key test methods that run in a specific order to validate your application comprehensively.
Test Execution Order
The tests are executed in a predefined sequence using pytest’s ordering:Health Check
test_health_check (Order 1)Verifies that the server is running and responding to requests by making a GET request to the host.
Authentication
test_auth (Order 2)Tests the authentication and connection flow by calling
test_connection with provided credentials and validating against expected responses.Metadata Retrieval
test_metadata (Order 3)Tests metadata retrieval by calling
get_metadata with credentials and comparing to expected responses.Preflight Checks
test_preflight_check (Order 4)Executes preflight checks using credentials and metadata, validating against expected responses.
Workflow Execution
test_run_workflow (Order 5)Tests the full workflow execution:
- Starts the workflow with credentials, metadata, and connection details
- Monitors the workflow until completion
- Raises a
WorkflowExecutionErrorif workflow does not complete successfully
Data Validation
test_data_validation (Order 6)Validates the extracted source data against schema definitions using Pandera.
The execution order is specified using the
@pytest.mark.order decorator. If you add custom test methods, use order values greater than 6 to run them after the built-in tests.Required Properties
TheBaseTest class requires several properties to be defined:
Path to the configuration file that defines test scenarios
Base path for extracted output files (set in the override file)
Base path for schema files used in data validation
Dictionary containing authentication credentials
Dictionary containing metadata configuration
Dictionary containing connection details
Configuration
The test framework uses a YAML configuration file to configure tests and workflows.Example Configuration
See a complete configuration example in the atlan-postgres-app repository.
Configuration Structure
Here’s a typical configuration structure:Data Validation
Thetest_data_validation method validates extracted data against schema definitions using Pandera, a powerful data validation library for pandas DataFrames.
Schema Files
Schema files define the expected structure and data types for extracted metadata:Example Schema Files
View complete schema examples in the atlan-postgres-app repository.
Custom Validation
You can override thetest_data_validation method to add custom validation logic:
Running Tests
Run tests using pytest from your project root:Test Output
The test framework provides detailed output for each test:Adding Custom Test Steps
To add additional test steps after the built-in ones:Multiple Test Scenarios
You can create multiple test scenarios by copying the test directory structure:Best Practices
Organize by Scenario
Organize by Scenario
Create separate test directories for different scenarios (basic extraction, filtered extraction, view handling, etc.).
Use Descriptive Names
Use Descriptive Names
Name test files and methods descriptively to make test results easy to understand.
Validate Thoroughly
Validate Thoroughly
Define comprehensive schema files that validate all expected fields and data types.
Test Edge Cases
Test Edge Cases
Create test scenarios for edge cases like empty databases, special characters, or large datasets.
Clean Up Resources
Clean Up Resources
Add cleanup steps to remove temporary files and resources after tests complete.
Version Control Config
Version Control Config
Keep test configuration files in version control, but never commit actual credentials.
Troubleshooting
Health Check Fails
Health Check Fails
- Verify the application server is running
- Check the host and port in your configuration
- Ensure firewall rules allow connections
Authentication Fails
Authentication Fails
- Verify credentials in the configuration file
- Check that the database user has necessary permissions
- Ensure the authentication type matches your database setup
Workflow Execution Fails
Workflow Execution Fails
- Check Temporal server logs for errors
- Verify worker is running and registered
- Review activity logs for specific error messages
Data Validation Fails
Data Validation Fails
- Check schema files match the actual extracted data structure
- Review Pandera error messages for specific validation failures
- Verify extracted output files exist at the expected paths
Next Steps
Best Practices
Learn best practices for building scalable applications.
SQL Applications
Build comprehensive SQL metadata extraction applications.
PostgreSQL Example
Explore a complete production-ready example with tests.
Pandera Documentation
Learn more about data validation with Pandera.