diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 9001ca33b6166a..b46e5987a43570 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -769,7 +769,10 @@ def getloadavg(self): return self.win_load_tracker.getloadavg() if hasattr(os, 'getloadavg'): - return os.getloadavg()[0] + try: + return os.getloadavg()[0] + except OSError: + pass return None diff --git a/Misc/NEWS.d/next/Tests/2023-07-13-02-14-57.gh-issue-99242.DHVhbD.rst b/Misc/NEWS.d/next/Tests/2023-07-13-02-14-57.gh-issue-99242.DHVhbD.rst new file mode 100644 index 00000000000000..c5dd3d2bdc322f --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-07-13-02-14-57.gh-issue-99242.DHVhbD.rst @@ -0,0 +1,3 @@ +:func:`os.getloadavg` may throw :exc:`OSError` when running regression tests under +certain conditions (e.g. chroot). This error is now caught and ignored, since +reporting load average is optional.