Skip to main content

astro dev pytest

info

The behavior and format of this command are the same for both Astro and Software.

Run unit tests for your data pipelines on Astro with pytest, a testing framework for Python. When you run this command, the Astro CLI creates a local Python environment that includes your DAG code, dependencies, and Astro Runtime Docker image. The CLI then runs any pytests in the tests directory of your Astro project and shows you the results of those tests in your terminal.

The command runs pytest in a container. If your test generates artifacts, such as code coverage reports, you can output the artifacts to the include folder of your Astro project so they can be accessed after the test has finished.

For more information on this functionality, see Test your Astro project locally.

info

This command requires Astro Runtime version 4.1.0+. For more information, see Astro Runtime Release Notes.

Usage

astro dev pytest

Options

OptionDescriptionPossible Values
<pytest-filepath>The filepath to an alternative pytest file or directory. Must be within the tests directoryAny valid filepath within the tests directory
-a, --argsArguments to pass to pytest. Surround the args in quotes.Any set of pytest command arguments surrounded by quotes
--build-secretsRun docker build --secret to mount a secret value to your Docker image.id=<your-secret-id>, src=<path-to-secret> . See Docker documentation.
-e, --envThe filepath to your environment variables. The default is .env)Any valid filepath within your Astro project
-i, --image-nameThe name of a pre-built custom Docker image to use with your project. The image must be available from a Docker registry hosted on your local machineA valid name for a pre-built Docker image based on Astro Runtime

Examples

# Specify env file at root of Astro project
astro dev pytest --env=myAlternativeEnvFile.env

# Specify an argument for pytest
astro dev pytest --args "–-cov-config path"

# Generate a coverage report in the include/coverage.xml file
astro dev pytest --args "--cov --cov-report xml:include/coverage.xml"

Was this page helpful?

Sign up for Developer Updates

Get a summary of new Astro features once a month.

You can unsubscribe at any time.
By proceeding you agree to our Privacy Policy, our Website Terms and to receive emails from Astronomer.