astronomer / astro-cli

CLI that makes it easy to create, test and deploy Airflow DAGs to Astronomer
https://www.astronomer.io
Other
334 stars 70 forks source link

`astro dev pytest -a "-m \"not <marker>\""` - Can't run tests without marker #1265

Open alex-astronomer opened 1 year ago

alex-astronomer commented 1 year ago

Describe the bug

When trying to run astro dev pytest and passing a custom marker in the args for the underlying pytest command, I receive an error that no file was found for my marker.

alexkennedy@Alexs-MacBook-Pro-2 airflow % astro dev pytest -a "-m \"not integration\""

Results in error message:

Running Pytest
This may take a minute if you have not run this command before…
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
            environment-variable.

Sending build context to Docker daemon  2.094MB
Step 1/1 : FROM quay.io/astronomer/astro-runtime:8.3.0
# Executing 7 build triggers
 ---> Using cache
 ---> Using cache
 ---> Using cache
 ---> Using cache
 ---> Using cache
 ---> Using cache
 ---> Using cache
 ---> f856f30e3b3a
Successfully built f856f30e3b3a
Successfully tagged airflow_450e8e/airflow:latest
ERROR: file or directory not found: integration"

============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0
rootdir: /usr/local/airflow
plugins: anyio-3.6.2
collected 0 items

============================ no tests ran in 0.01s =============================
Error: failed to execute cmd: exit status 4

Running with command

pytest -m "not integration"

Correctly runs the tests, skipping any tests that are marked with @pytest.mark.integration.

What CLI Version did you experience this bug?

1.15.1

This CLI bug is related to which Astronomer Platform?

What Operating System is the above CLI installed on?

macOS Ventura 13.4

🪜 Steps To Reproduce

Create 2 tests, one marked with integration and one without.

import pytest

def test_unit():
    print("hello unit test")

@pytest.mark.integration
def test_integration():
    print("hello integration test")

Running this test with pytest -m "not integration" should run successfully. This should skip one test, and run one test. This shows in the output of the pytest command with running with astro CLI.

Then, run these tests as part of an Airflow Astro repository project.

Running the command astro dev pytest -a "-m \"not integration\"" results in an error like ERROR: file or directory not found: integration".

KnutKiesel commented 1 month ago

Not solving the problem, but a workaround we found:

echo -e '[pytest]\naddopts = -m "not integration"' > pytest.ini
astro dev pytest

Not an expert in go, but I think it could be solved by replacing this line by something similar to this snippet.