MagicStack/uvloop

test_process_env_2 not portable to non-FHS systems

Opened this issue · 0 comments

  • uvloop version: 0.21.0
  • Python version: 3.10
  • Platform: GNU Guix

This test code:

    def test_process_env_2(self):
        async def test():
            cmd = 'env'
            env = {}  # empty environment
            proc = await asyncio.create_subprocess_exec(
                cmd,
                env=env,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)

            out, _ = await proc.communicate()
            self.assertEqual(out, b'')
            self.assertEqual(proc.returncode, 0)

        self.loop.run_until_complete(test())

fails like:

=================================== FAILURES ===================================
______________________ Test_UV_Process.test_process_env_2 ______________________
Traceback (most recent call last):
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/tmp/guix-build-python-uvloop-0.21.0.drv-0/uvloop-0.21.0/tests/test_process.py", line 67, in test_process_env_2
    self.loop.run_until_complete(test())
  File "uvloop/loop.pyx", line 1518, in uvloop.loop.Loop.run_until_complete
  File "/tmp/guix-build-python-uvloop-0.21.0.drv-0/uvloop-0.21.0/tests/test_process.py", line 57, in test
    proc = await asyncio.create_subprocess_exec(
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/subprocess.py", line 218, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "uvloop/loop.pyx", line 2841, in subprocess_exec
  File "uvloop/loop.pyx", line 2799, in __subprocess_run
  File "uvloop/handles/process.pyx", line 611, in uvloop.loop.UVProcessTransport.new
  File "uvloop/dns.pyx", line 112, in uvloop.loop.__convert_pyaddr_to_sockaddr
FileNotFoundError: [Errno 2] No such file or directory
_____________________ Test_AIO_Process.test_process_env_2 ______________________
Traceback (most recent call last):
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/tmp/guix-build-python-uvloop-0.21.0.drv-0/uvloop-0.21.0/tests/test_process.py", line 67, in test_process_env_2
    self.loop.run_until_complete(test())
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/tmp/guix-build-python-uvloop-0.21.0.drv-0/uvloop-0.21.0/tests/test_process.py", line 57, in test
    proc = await asyncio.create_subprocess_exec(
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/subprocess.py", line 218, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/base_events.py", line 1667, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/unix_events.py", line 207, in _make_subprocess_transport
    transp = _UnixSubprocessTransport(self, protocol, args, shell,
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/base_subprocess.py", line 36, in __init__
    self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/asyncio/unix_events.py", line 799, in _start
    self._proc = subprocess.Popen(
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/gnu/store/jjcka1g6sk2cvwx8nm4fdwpdq3vll0v0-python-3.10.7/lib/python3.10/subprocess.py", line 1845, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'env'

This is because on non-file-hierarchy-standard systems like GNU Guix and Nix, env is not found at some fixed location burnt on the implicit PATH value; instead it must be looked from PATH, but the tests clears it.