Skip to content

test: ensure integration pytest works in collection mode#865

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
richm:test-integration-pytest
May 1, 2026
Merged

test: ensure integration pytest works in collection mode#865
richm merged 1 commit intolinux-system-roles:mainfrom
richm:test-integration-pytest

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented Apr 30, 2026

The tests/ directory has a library sub-directory with a symlink to the
network_connections.py module. This was causing problems because the logic
in get_modules_and_utils_paths.yml really wants the real files and
directories, not the symlinks, and for some reason the bash -f test
is returning true for the symlink. Instead, ensure that we do not use
the link by using -L to screen it out.

Also added the collection paths to the search.

Make the path arrays have unique values.

Use the realpath filter to see the full actual path.

Signed-off-by: Rich Megginson rmeggins@redhat.com

Summary by Sourcery

Adjust test collection path discovery to ignore symlinked modules, include additional collection plugin paths, and normalize discovered paths for integration pytest.

Bug Fixes:

  • Prevent symlinked network_connections.py in the tests library directory from being incorrectly treated as the real module during path discovery.

Enhancements:

  • Deduplicate module and module_utils search paths when constructing collection path lists.
  • Extend module and module_utils search paths to include collection plugin directories under plugins/modules and plugins/module_utils.
  • Normalize the resolved tests directory path in the integration pytest playbook using a realpath filter.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts integration pytest support to avoid symlinked test library paths, expands module and module_utils search paths to include collection plugin directories, deduplicates all constructed path lists, and resolves the tests directory to its real filesystem path.

File-Level Changes

Change Details Files
Deduplicate all dynamically constructed collection and module search paths in get_modules_and_utils_paths.yml.
  • Apply the Jinja2 unique filter to the combined collection paths list after select.
  • Apply the Jinja2 unique filter to the modules search path list after select.
  • Apply the Jinja2 unique filter to the module_utils search path list after select.
tests/tasks/get_modules_and_utils_paths.yml
Expand module and module_utils search paths to include collection plugin directories used by pytest.
  • Augment modules_search_path with ../../plugins/modules and ../plugins/modules alongside existing library paths.
  • Augment module_utils_search_path with ../../plugins/module_utils and ../plugins/module_utils alongside existing module_utils paths.
tests/tasks/get_modules_and_utils_paths.yml
Change module resolution shell logic to skip symlinked network_connections.py and only act on real files.
  • In the top-level modules_search_path loop, explicitly continue when network_connections.py is a symlink (-L) before checking for a regular file (-f).
  • In the ansible_collections///plugins/modules loop, explicitly continue when network_connections.py is a symlink (-L) before checking for a regular file (-f).
tests/tasks/get_modules_and_utils_paths.yml
Ensure the integration pytest playbook uses the canonical tests directory path.
  • Wrap the first_found lookup for tests_directory with the realpath filter so pytest uses a fully resolved path.
tests/playbooks/integration_pytest_python3.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In the shell loops, you could simplify the symlink handling by using a single condition like [ -f "$file" ] && [ ! -L "$file" ] instead of a separate -L/-f branch to reduce duplication and make the intent clearer.
  • Now that unique is used in the Jinja expressions, the final | list is redundant because unique already returns a list, so you can remove | list for slightly cleaner templates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the shell loops, you could simplify the symlink handling by using a single condition like `[ -f "$file" ] && [ ! -L "$file" ]` instead of a separate `-L`/`-f` branch to reduce duplication and make the intent clearer.
- Now that `unique` is used in the Jinja expressions, the final `| list` is redundant because `unique` already returns a list, so you can remove `| list` for slightly cleaner templates.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.68%. Comparing base (1b57520) to head (2fdb73b).
⚠️ Report is 92 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #865      +/-   ##
==========================================
- Coverage   43.11%   42.68%   -0.43%     
==========================================
  Files          12       13       +1     
  Lines        3124     3160      +36     
==========================================
+ Hits         1347     1349       +2     
- Misses       1777     1811      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@richm
Copy link
Copy Markdown
Contributor Author

richm commented Apr 30, 2026

[citest]

@richm richm force-pushed the test-integration-pytest branch from d69b82c to 8bd59c4 Compare April 30, 2026 23:17
Refactor the common code in tests_unit.yml and the integration pytest
into a single block of code.

The tests/ directory has a library sub-directory with a symlink to the
network_connections.py module.  This was causing problems because the logic
in get_modules_and_utils_paths.yml really wants the real files and
directories, not the symlinks, and for some reason the bash `-f` test
is returning `true` for the symlink.  Instead, ensure that we do not use
the link by using `-L` to screen it out.

Also added the collection paths to the search.

Make the path arrays have unique values.

Use the `realpath` filter to see the full actual path.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
@richm richm force-pushed the test-integration-pytest branch from 8bd59c4 to 2fdb73b Compare April 30, 2026 23:23
@richm
Copy link
Copy Markdown
Contributor Author

richm commented Apr 30, 2026

[citest]

@richm richm merged commit 3267ddb into linux-system-roles:main May 1, 2026
47 of 48 checks passed
@richm richm deleted the test-integration-pytest branch May 1, 2026 12:55
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