Skip to content

AAP-51352 Change metric used to determine if pytest is being used#858

Open
AlanCoding wants to merge 1 commit intoansible:develfrom
AlanCoding:test_is_testing
Open

AAP-51352 Change metric used to determine if pytest is being used#858
AlanCoding wants to merge 1 commit intoansible:develfrom
AlanCoding:test_is_testing

Conversation

@AlanCoding
Copy link
Copy Markdown
Member

@AlanCoding AlanCoding commented Oct 6, 2025

Description

What I did in #853 turned out to have a critical flaw, revealed in ansible/awx#16114

Basically, pytest automatically sets settings.DEBUG to False and this is accepted standard practice.

After doing some more research, these environment variables are relatively standard and reliable. Supposedly it still might not be picked up in fixtures, but I have never observed that.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test update
  • Refactoring (no functional changes)
  • Development environment change
  • Configuration change

Note

Introduce is_testing() (env-based pytest detection) and use it in ServiceID creation logic; add corresponding test.

  • Utils:
    • Add is_testing() in ansible_base/lib/utils/settings.py using PYTEST_CURRENT_TEST/PYTEST_XDIST_WORKER env vars.
  • Resource Registry:
    • Update service_identifier.service_id() to use is_testing() instead of checking sys.argv for pytest.
  • Tests:
    • Add test_is_testing and import is_testing in test_settings.py.

Written by Cursor Bugbot for commit 3760236. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 6, 2025

DVCS PR Check Results:

PR appears valid (JIRA key(s) found)

@AlanCoding AlanCoding marked this pull request as ready for review October 6, 2025 19:00
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Oct 6, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
75.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@AlanCoding
Copy link
Copy Markdown
Member Author

There is an AWX analog of this at:

https://github.com/ansible/awx/blob/0d18308112edf8507602cc2f426197520b6009a7/awx/main/utils/common.py#L137-L147

Hopefully I can remove that in favor of this.

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.

1 participant