Testing Your Changes
Framework and Structure
- We use
pytestas our testing framework. Do not use theunittestpackage. - Test files should mirror the package structure:
project_root/
├── amee_utils/
│ ├── utils/
│ │ ├── __init__.py
│ │ └── some_utility.py
│ ├── feature_generator/
│ │ ├── __init__.py
│ │ └── generator.py
│ ├── writer.py
│ └── loader.py
├── tests/
│ ├── utils/
│ │ ├── __init__.py
│ │ └── test_some_utility.py
│ ├── feature_generator/
│ │ ├── __init__.py
│ │ └── test_generator.py
│ ├── test_writer_UCWriter.py
│ ├── test_writer_DeltaWriter.py
│ └── test_loader.py
- Test files should be prefixed with
test_ - The name should match the module being tested
- Example:
writer.py→test_writer_UCWriter.pyandtest_writer_DeltaWriter.py
Writing Tests
- Use fixtures for common setup and teardown
-
Tests that require
Sparkcan use the existing spark fixture inconftest.py:conftest.py"""Default utility fixtures for pytest.""" import pytest from pyspark.sql import SparkSession @pytest.fixture(scope="module") def spark(): spark_builder = SparkSession.builder.appName("Test") spark_builder.config("spark.master", "local[1]") spark = spark_builder.getOrCreate() yield spark spark.stop()This spark fixture can then be used in any test module as follows:
Running tests
Running all tests
You can run all existing tests and your added tests by running the following command:
All existing tests should pass without any alteration. If an existing test requires alteration, this should be investigated and the change should be marked as a breaking change in the Pull Request.
Running tests with code coverage
To make sure your tests are covering the code sufficiently, please run the tests with code coverage:
Make sure that the coverage does not drop significantly, and that your additional code is appropriately covered.
Documentation Changes
Info
We use NumPy formatting for docstrings. Please make sure your docstrings are appropriately formatted in order to reflect correctly in the API Reference section.
To preview your changes made to the documentation, and to test that the updated documentation reflects appropriately, please run the following:
You can then open a local version of the documents in your browser (localhost), and thoroughly review your changes
Tip
Please be sure to check the API Reference for your added code to make sure your docstrings have pulled through correctly.