Skip to content

fix(parse): handle PYTEST_THEME env var in DAG integrity test#2028

Merged
jlaneve merged 1 commit intomainfrom
josh-fell/fix-pytest-theme-mock
Mar 5, 2026
Merged

fix(parse): handle PYTEST_THEME env var in DAG integrity test#2028
jlaneve merged 1 commit intomainfrom
josh-fell/fix-pytest-theme-mock

Conversation

@josh-fell
Copy link
Contributor

Fixes a bug where astro dev parse fails when projects specify --color=yes in their pytest configuration. The monkeypatched os.getenv() in the DAG integrity test templates returns MOCKED_PYTEST_THEME_VALUE for unset environment variables, which pytest validates against known Pygment styles and rejects. This change adds special handling for PYTEST_THEME (similar to the existing JENKINS_HOME fix from #601), returning None when the variable is unset instead of a mocked value.

🎟 Issue(s)

Resolves a bug where pytest fails with:

ERROR: PYTEST_THEME environment variable had an invalid value: 'MOCKED_PYTEST_THEME_VALUE'.
Only valid pygment styles are allowed.

Related to #601 (similar fix pattern for JENKINS_HOME)

🧪 Functional Testing

  1. Create an Astro project with pytest configured to use --color=yes:

    astro dev init
  2. Add to pytest.ini or pyproject.toml:

    [tool.pytest.ini_options]
    addopts = "--color=yes"
  3. Run parse command:

    astro dev parse
  4. Verify it completes successfully without PYTEST_THEME error

Before this fix: Command fails with "PYTEST_THEME environment variable had an invalid value"
After this fix: Command succeeds and DAGs parse correctly

📸 Screenshots

N/A - This is a bug fix that prevents an error message, no visual changes

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests (N/A - no existing tests for monkeypatch functions)
  • Tested against Astro-API (if necessary). (N/A - local CLI fix only)
  • Tested against Houston-API and Astronomer (if necessary). (N/A - local CLI fix only)
  • Communicated to/tagged owners of respective clients potentially impacted by these changes. (N/A - internal fix)
  • Updated any related documentation (N/A - fixes existing behavior)

Files Changed

  • airflow/include/airflow2/dagintegritytestdefault.py - Added PYTEST_THEME special case
  • airflow/include/airflow3/dagintegritytestdefault.py - Added PYTEST_THEME special case
  • go.mod - Fixed go version format from 1.24.0 to 1.24

Notes for Reviewers

This follows the exact same pattern as the JENKINS_HOME fix that was added for issue #601. The monkeypatch templates already have infrastructure for handling environment variables that need special treatment - this simply adds PYTEST_THEME to that list.

When running `astro dev parse`, the monkeypatched os.getenv() returns
MOCKED_PYTEST_THEME_VALUE for unset environment variables. Pytest
validates PYTEST_THEME against known Pygment styles and fails with:

  ERROR: PYTEST_THEME environment variable had an invalid value:
  'MOCKED_PYTEST_THEME_VALUE'. Only valid pygment styles are allowed.

This occurs when Astro projects specify "--color=yes" in pytest configs,
causing pytest to check the PYTEST_THEME environment variable.

Solution: Return None for PYTEST_THEME when no default is provided,
following the same pattern used for the JENKINS_HOME fix (#601).

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@josh-fell josh-fell requested a review from a team as a code owner March 5, 2026 02:10
@josh-fell josh-fell force-pushed the josh-fell/fix-pytest-theme-mock branch from b708c5d to 029b3af Compare March 5, 2026 02:35
@coveralls-official
Copy link

Pull Request Test Coverage Report for Build cfe1dabf-371b-4ee1-8611-3f65c75e05a5

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 35.914%

Totals Coverage Status
Change from base Build 408796d1-867a-49d6-a9f1-470124cda0c8: 0.0%
Covered Lines: 24288
Relevant Lines: 67629

💛 - Coveralls

@jlaneve jlaneve merged commit 49f2b8e into main Mar 5, 2026
5 of 6 checks passed
@jlaneve jlaneve deleted the josh-fell/fix-pytest-theme-mock branch March 5, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants