-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[py] Use mock.patch for environment variables in tests #15607
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
[py] Use mock.patch for environment variables in tests #15607
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
CI failures are caused by #15608 ... all other tests pass. |
User description
💥 What does this PR do?
This PR adds better use of
unittest.mock.patchfor mocking environment variables in some of the internal Python tests.Several tests were directly modifying environment variables (via
os.environ) in tests, and often not resetting them at the end of the test. It is generally bad practice to modify environment variables since they can stay set to the wrong value if the test fails. Also, not resetting them at the end of the test can leak state into another test. These changes make sure all environment variables are changed within a mocked/patched copy ofos.environ.🔄 Types of changes
PR Type
Bug fix, Tests
Description
Replaced direct
os.environmodifications withunittest.mock.patch.Improved test isolation by mocking environment variables.
Updated tests across multiple browser service test files.
Ensured environment variable changes do not leak between tests.
Changes walkthrough 📝
chrome_service_tests.py
Refactored Chrome service tests to use `patch.dict`py/test/selenium/webdriver/chrome/chrome_service_tests.py
os.environmodification withpatch.dict.test_updates_path_after_setting_env_variable.proxy_tests.py
Refactored Chrome proxy tests to use `patch.dict`py/test/selenium/webdriver/chrome/proxy_tests.py
patch.dictto mock proxy-related environment variables.os.environin tests.edge_service_tests.py
Refactored Edge service tests to use `patch.dict`py/test/selenium/webdriver/edge/edge_service_tests.py
os.environmodification withpatch.dict.firefox_service_tests.py
Refactored Firefox service tests to use `patch.dict`py/test/selenium/webdriver/firefox/firefox_service_tests.py
os.environmodification withpatch.dict.safari_service_tests.py
Refactored Safari service tests to use `patch.dict`py/test/selenium/webdriver/safari/safari_service_tests.py
patch.dictto mock environment variables.remote_connection_tests.py
Refactored remote connection tests to use `patch.dict`py/test/unit/selenium/webdriver/remote/remote_connection_tests.py
os.environmanipulation withpatch.dict.