Skip to content

Add tox for Python testing #2285

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 4 commits into from
Apr 27, 2025
Merged

Add tox for Python testing #2285

merged 4 commits into from
Apr 27, 2025

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Apr 24, 2025

User description

Description

This PR adds a minimal tox configuration (tox.ini) for running the Python example tests across multiple Python versions. (see: https://tox.wiki)

You can run the tests against all Python versions 3.9-3.13 by running tox, or you can run against a specific environment: tox -e py313

I didn't change CI to use this because, we are already testing against all supported Python versions in the workflow.

Motivation and Context

This is just a convenience for running local tests and can be used in the future when we add linting.

Types of changes

  • Test infrastructure added

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Tests, Enhancement


Description

  • Add tox.ini for multi-version Python test automation

  • Update requirements.txt to include tox dependency

  • Enable local testing across Python 3.9-3.13 with tox


Changes walkthrough 📝

Relevant files
Tests
tox.ini
Add tox.ini for Python multi-version test automation         

examples/python/tox.ini

  • Introduces new tox.ini configuration file
  • Defines environments for Python 3.9 through 3.13
  • Configures pytest command with verbose and summary options
  • Enables skipping missing interpreters for flexible local testing
  • +30/-0   
    Enhancement
    requirements.txt
    Add tox to Python requirements for local testing                 

    examples/python/requirements.txt

  • Adds tox==4.25.0 to requirements
  • Ensures tox is available for local test runs
  • +1/-0     

    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

    netlify bot commented Apr 24, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 1cd9a49

    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

    qodo-merge-pro bot commented Apr 24, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Security
    Limit environment variable exposure

    *The passenv = configuration is overly permissive as it passes all environment
    variables to the test environment. This can lead to inconsistent test results
    when tests depend on environment-specific variables. Consider limiting to only
    necessary environment variables.

    examples/python/tox.ini [21-30]

     [testenv]
     description = run tests
    -passenv = *
    +passenv = 
    +    PYTHONPATH
    +    HOME
    +    CI
     deps =
         -r requirements.txt
     commands =
         # "-vv" means extra verbose
         # "-r fEsxXp" means show extra test summary info as specified by:
         #   (f)ailed, (E)rror, (s)kipped, (x)failed, (X)passed, (p)assed
         pytest -vv -r fEsxXp {posargs:.}
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion improves security by limiting environment variable exposure instead of passing all variables with "passenv = *". This reduces the risk of test inconsistencies and potential security issues by explicitly specifying only necessary environment variables.

    Medium
    • Update

    @harsha509
    Copy link
    Member

    HI @cgoldberg ,

    Would it be helpful to add this information to the Selenium documentation page at https://www.selenium.dev/documentation/webdriver/getting_started/using_selenium/?

    Thanks,
    Sri

    @cgoldberg
    Copy link
    Contributor Author

    cgoldberg commented Apr 27, 2025

    @harsha509

    Yes, it makes sense to add a note to that page.

    I just had a look at it and there is some outdated information for running the Python tests. It refers to using unittest and shows examples of doing unittest setup/teardown methods. The tests all require pytest nowadays, and use fixtures for setup/teardown.

    I will update that page with more relevant information for running Python tests.

    @cgoldberg
    Copy link
    Contributor Author

    @harsha509

    I just viewed that page again, and it actually doesn't make sense to add any more info there. The change in this PR is only relevant for running the Python example tests in this repo, not selenium in general.

    A more relevant place for this information would be in ./examples/python/README.md in this repo. I will add a note there.

    @cgoldberg
    Copy link
    Contributor Author

    @harsha509 ok.. README is updated.

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

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

    Ah, makes sense.

    LGTM!
    Thank you @cgoldberg !

    @harsha509 harsha509 merged commit d716f06 into SeleniumHQ:trunk Apr 27, 2025
    9 checks passed
    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.

    2 participants