> ## Documentation Index
> Fetch the complete documentation index at: https://astronomer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# astro dev pytest

<Info>The behavior and format of this command are the same for both Astro and Astro Private Cloud.</Info>

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](/docs/cli/v1.38/test-your-astro-project-locally).

<Info>This command requires Astro Runtime version `3.1.1`+. For more information, see [Astro Runtime Release Notes](/docs/runtime/runtime-release-notes#astro-runtime-3-1-1).</Info>

## Usage

```sh wrap theme={null}
astro dev pytest
```

## Options

| Option               | Description                                                                                                              | Possible Values                                                                                                                          |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `<pytest-filepath>`  | The filepath to an alternative pytest file or directory. Must be within the `tests` directory                            | Any valid filepath within the `tests` directory                                                                                          |
| `-a`, `--args`       | Arguments to pass to pytest. Surround the args in quotes.                                                                | Any set of pytest command arguments surrounded by quotes                                                                                 |
| `--build-secrets`    | Run `docker build --secret` to mount a secret value to your Docker image.                                                | `id=<your-secret-id>, src=<path-to-secret> .` See [Docker documentation](https://docs.docker.com/build/building/secrets/#secret-mounts). |
| `-e`, `--env`        | The filepath to your environment variables. The default is `.env`)                                                       | Any valid filepath within your Astro project                                                                                             |
| `-i`, `--image-name` | The name of a pre-built custom Docker image to use with your project. The image must be available on your local machine. | A valid name for a pre-built Docker image based on Astro Runtime                                                                         |

## Examples

```bash wrap theme={null}
# 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"
```

## Related commands

* [`astro dev init`](/docs/cli/v1.38/astro-dev-init)
* [`astro dev start`](/docs/cli/v1.38/astro-dev-start)
* [`astro deploy`](/docs/cli/v1.38/astro-deploy)
