Replace hardcoded python3 in pytest file: How to do this properly using the python macros?
Hi all, python-subprocess-tee fails to build for 15.x (using only python3.11), as one of the pytest checks contains a hardcoded python3 executable name. I solved this quick and dirty using this snippet: # replace hardcoded python3 in test/test_unit.py sed -i "s/python3/python3.11/g" test/test_unit.py
https://build.opensuse.org/package/show/home:ojkastl_buildservice:Branch_sys...
On Tumbleweed it succeeds, as there is a python3 executable. Is there a nice way to do this without hardcoding the python version? The best I could come up with is to use a %if condition for "SLES15 or Tumbleweed", but that would be hardcoding the python version... Kind Regards, Johannes -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg http://www.b1-systems.de GF: Ralph Dehner Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Am Freitag, 5. Mai 2023, 14:48:54 CEST schrieb Johannes Kastl:
# replace hardcoded python3 in test/test_unit.py sed -i "s/python3/python3.11/g" test/test_unit.py
The code should not hardcode this, it should use "sys.executable" from the sys module to determine its own interpreter. This needs to be submitted as a fix upstream. Greetings, Dirk
Hi Dirk, long time no read... :-) On 05.05.23 at 15:55 Dirk Müller wrote:
Am Freitag, 5. Mai 2023, 14:48:54 CEST schrieb Johannes Kastl:
# replace hardcoded python3 in test/test_unit.py sed -i "s/python3/python3.11/g" test/test_unit.py
The code should not hardcode this, it should use "sys.executable" from the sys module to determine its own interpreter.
I think in this case it is intended to not use a python-internal call. subprocess-tee is meant to run non-python commands from within python.
https://github.com/pycontribs/subprocess-tee/blob/main/test/test_unit.py#L33
cmd = ["python3", "--version"] old_result = subprocess.run( cmd, # shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False, ) result = run(cmd)
So I guess this needs to be replaced during build with the proper python executable. But please, I am not a python expert, so correct me if I am wrong. Kind Regards, Johannes -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg http://www.b1-systems.de GF: Ralph Dehner Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
Am 05.05.23 um 20:05 schrieb Johannes Kastl:
On 05.05.23 at 15:55 Dirk Müller wrote:
The code should not hardcode this, it should use "sys.executable" from the sys module to determine its own interpreter.
I think in this case it is intended to not use a python-internal call. subprocess-tee is meant to run non-python commands from within python.
https://github.com/pycontribs/subprocess-tee/blob/main/test/test_unit.py#L33
But please, I am not a python expert, so correct me if I am wrong.
You're wrong ;) The tests should use the same interpreter as they are called with. So please replace it with sys.executable and submit the patch upstream, if possible. - Ben
Good Evening Ben, On 05.05.23 at 20:08 Ben Greiner wrote:
Am 05.05.23 um 20:05 schrieb Johannes Kastl:
On 05.05.23 at 15:55 Dirk Müller wrote:
The code should not hardcode this, it should use "sys.executable" from the sys module to determine its own interpreter.
I think in this case it is intended to not use a python-internal call. subprocess-tee is meant to run non-python commands from within python.
https://github.com/pycontribs/subprocess-tee/blob/main/test/test_unit.py#L33
But please, I am not a python expert, so correct me if I am wrong.
You're wrong ;)
:-)
The tests should use the same interpreter as they are called with. So please replace it with sys.executable and submit the patch upstream, if possible.
Will do so. Have a nice weekend! Kind Regards, Johannes -- Johannes Kastl Linux Consultant & Trainer Tel.: +49 (0) 151 2372 5802 Mail: kastl@b1-systems.de B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg http://www.b1-systems.de GF: Ralph Dehner Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
participants (3)
-
Ben Greiner
-
Dirk Müller
-
Johannes Kastl