Skip to content
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

Do not use EnvironmentError in tests, use OSError instead #121571

Closed
sobolevn opened this issue Jul 10, 2024 · 0 comments
Closed

Do not use EnvironmentError in tests, use OSError instead #121571

sobolevn opened this issue Jul 10, 2024 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Jul 10, 2024

Bug report

Since 3.3 EnvironmentError is just an alias for OSError. There are several places where it is still used. I propose to modernize the code. Just like we did with IOError.

diff --git Lib/test/support/__init__.py Lib/test/support/__init__.py
index 18455bb6e0f..7f657931958 100644
--- Lib/test/support/__init__.py
+++ Lib/test/support/__init__.py
@@ -387,7 +387,7 @@ def skip_if_buildbot(reason=None):
         reason = 'not suitable for buildbots'
     try:
         isbuildbot = getpass.getuser().lower() == 'buildbot'
-    except (KeyError, EnvironmentError) as err:
+    except (KeyError, OSError) as err:
         warnings.warn(f'getpass.getuser() failed {err}.', RuntimeWarning)
         isbuildbot = False
     return unittest.skipIf(isbuildbot, reason)
diff --git Lib/test/test_subprocess.py Lib/test/test_subprocess.py
index 8b69cd03ba7..9412a2d737b 100644
--- Lib/test/test_subprocess.py
+++ Lib/test/test_subprocess.py
@@ -1407,7 +1407,7 @@ def open_fds():
         t = threading.Thread(target=open_fds)
         t.start()
         try:
-            with self.assertRaises(EnvironmentError):
+            with self.assertRaises(OSError):
                 subprocess.Popen(NONEXISTING_CMD,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jul 10, 2024
@sobolevn sobolevn self-assigned this Jul 10, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Jul 10, 2024
sobolevn added a commit to sobolevn/cpython that referenced this issue Jul 10, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 10, 2024
…` instead (pythonGH-121572)

(cherry picked from commit e282236)

Co-authored-by: sobolevn <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 10, 2024
…` instead (pythonGH-121572)

(cherry picked from commit e282236)

Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Jul 10, 2024
…r` instead (GH-121572) (#121575)

gh-121571: Do not use `EnvironmentError` in tests, use `OSError` instead (GH-121572)
(cherry picked from commit e282236)

Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn added a commit that referenced this issue Jul 10, 2024
…r` instead (GH-121572) (#121574)

gh-121571: Do not use `EnvironmentError` in tests, use `OSError` instead (GH-121572)
(cherry picked from commit e282236)

Co-authored-by: sobolevn <mail@sobolevn.me>
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant