8000 Do not use `EnvironmentError` in tests, use `OSError` instead · Issue #121571 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Do not use EnvironmentError in tests, use OSError instead #121571
Closed
@sobolevn

Description

@sobolevn

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

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0