Skip to content

[py] fix test discovery for pytest #15415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Mar 13, 2025

User description

Motivation and Context

This PR fixes test discovery for pytest, since it was not configured correctly in pyproject.toml.

Due to the naming convention of most of the Python tests, test discovery was not correctly finding tests to execute. You could only run tests by explicitly calling each test file, not by running the entire suite or directory.

For example... you could run pytest py/test/selenium/webdriver/common/window_tests.py just fine, but running pytest py/test/selenium/webdriver/common or pytest py/test/selenium would run nothing.

Without this fix, only 31 of the 1106 tests were able to be run!

(Note: this is only really evident when running pytest directly for local testing, since the bazel build tasks used for testing/CI call each test file explicitly and don't use test discovery)

Before this change:

$ pytest py/test --collect-only -q | head -n -2 | wc -l
31

After this change:

$ pytest py/test --collect-only -q | head -n -2 | wc -l
1106

Types of changes

  • 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 change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Bug fix


Description

  • Fixed pytest test discovery by updating python_files in pyproject.toml.

  • Enabled discovery of files with *_tests.py naming convention.

  • Improved test suite execution from 31 to 1106 tests.


Changes walkthrough 📝

Relevant files
Configuration changes
pyproject.toml
Update pytest configuration for test discovery                     

py/pyproject.toml

  • Added *_tests.py to python_files for pytest discovery.
  • Ensured all test files are correctly identified and executed.
  • +1/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @cgoldberg cgoldberg merged commit c485a62 into SeleniumHQ:trunk Mar 17, 2025
    12 of 17 checks passed
    @cgoldberg cgoldberg deleted the py-test-discovery branch March 17, 2025 01:21
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Mar 23, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant