diff options
author | Chandan Singh <chandan@chandansingh.net> | 2020-10-26 21:23:49 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-10-29 12:27:40 +0000 |
commit | 8fdab36c83aaf1872a39cc9f31db25a95b1240c1 (patch) | |
tree | d9bd6bb896b4e337396bfcdea1004320880c99bc | |
parent | 8616fc5b453003e1a56bb423706549dd3a80ad4b (diff) | |
download | buildstream-8fdab36c83aaf1872a39cc9f31db25a95b1240c1.tar.gz |
testutils/platform: Refactor to be compatible with Python 3.9chandan/py39-platform
Starting from Python 3.9, it seems like the `_replace()` method no
longer works on `platform.uname_result` objects, that are returned by
`platform.uname()`. This causes some of our tests to fail on Python 3.9.
See https://bugs.python.org/issue42163 for upstream issue.
Fix it by slightly changing the way we override the values of the
`platform.uname()` function, such that it works on both Python 3.9 and
3.8 (and below).
-rw-r--r-- | tests/testutils/platform.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/testutils/platform.py b/tests/testutils/platform.py index f8faf286e..d8078062a 100644 --- a/tests/testutils/platform.py +++ b/tests/testutils/platform.py @@ -17,6 +17,7 @@ # Authors: # Angelos Evripiotis <jevripiotis@bloomberg.net> +import collections from contextlib import contextmanager import platform @@ -32,15 +33,20 @@ import platform @contextmanager def override_platform_uname(*, system=None, machine=None): orig_func = platform.uname - result = platform.uname() + orig_system, node, release, version, orig_machine, processor = platform.uname() - if system is not None: - result = result._replace(system=system) - if machine is not None: - result = result._replace(machine=machine) + system = system or orig_system + machine = machine or orig_machine def override_func(): - return result + # NOTE: + # 1. We can't use `_replace` here because of this bug in + # Python 3.9.0 - https://bugs.python.org/issue42163. + # 2. We need to create a new subclass because the constructor of + # `platform.uname_result` doesn't share the same interface between + # Python 3.8 and 3.9. + uname_result = collections.namedtuple("uname_result", "system node release version machine processor") + return uname_result(system, node, release, version, machine, processor) platform.uname = override_func try: |