X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Futils%2Flttngtest%2Fenvironment.py;h=d9777810bdeb90fa7c4b7563598c43289304a8f6;hb=2d2198ca03187a1bc1795ddf235c56de8ddea4d1;hp=2e4b48569909705ceb400a5c05958f8a80a65511;hpb=7cb804198ecae54f791b76db058916c3cf2c48d9;p=lttng-tools.git diff --git a/tests/utils/lttngtest/environment.py b/tests/utils/lttngtest/environment.py index 2e4b48569..d9777810b 100644 --- a/tests/utils/lttngtest/environment.py +++ b/tests/utils/lttngtest/environment.py @@ -82,7 +82,7 @@ class WaitTraceTestApplication: tempfile.mktemp( prefix="app_", suffix="_start_tracing", - dir=environment.lttng_home_location, + dir=self._compat_open_path(environment.lttng_home_location), ) ) self._has_returned = False @@ -95,7 +95,9 @@ class WaitTraceTestApplication: # File that the application will create to indicate it has completed its initialization. app_ready_file_path: str = tempfile.mktemp( - prefix="app_", suffix="_ready", dir=environment.lttng_home_location + prefix="app_", + suffix="_ready", + dir=self._compat_open_path(environment.lttng_home_location), ) test_app_args = [str(binary_path)] @@ -140,7 +142,7 @@ class WaitTraceTestApplication: return_code=self._process.returncode ) ) - open(self._app_start_tracing_file_path, mode="x") + open(self._compat_open_path(self._app_start_tracing_file_path), mode="x") def wait_for_exit(self) -> None: if self._process.wait() != 0: @@ -155,6 +157,19 @@ class WaitTraceTestApplication: def vpid(self) -> int: return self._process.pid + @staticmethod + def _compat_open_path(path): + # type: (pathlib.Path) + """ + The builtin open() in python >= 3.6 expects a path-like object while + prior versions expect a string or bytes object. Return the correct type + based on the presence of the "__fspath__" attribute specified in PEP-519. + """ + if hasattr(path, "__fspath__"): + return path + else: + return str(path) + def __del__(self): if not self._has_returned: # This is potentially racy if the pid has been recycled. However,