kevlened / pytest-parallel

A pytest plugin for parallel and concurrent testing
https://github.com/browsertron/pytest-parallel/issues/104#issuecomment-1293941066
MIT License
313 stars 59 forks source link

Please support Python 3.9 #89

Closed isac322 closed 3 years ago

isac322 commented 3 years ago

When I run pytest . --workers auto with Python 3.9, this error occur.

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/_pytest/main.py", line 255, in wrap_session
INTERNALERROR>     config.hook.pytest_sessionstart(session=session)
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/manager.py", line 84, in <lambda>
INTERNALERROR>     self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pytest_parallel/__init__.py", line 219, in pytest_sessionstart
INTERNALERROR>     os.environ = ThreadLocalEnviron(os.environ)
INTERNALERROR>   File "/.../venv/lib/python3.9/site-packages/pytest_parallel/__init__.py", line 122, in __init__
INTERNALERROR>     env.putenv,
INTERNALERROR> AttributeError: '_Environ' object has no attribute 'putenv'

So I check the code, it uses os.environ.putenv but Python doesn't have the API. Then only have os.putenv.

On Python 3.8 they are exists.

Python 3.8.6 (default, Dec 11 2020, 14:45:03)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> e = os.environ
>>> e.putenv
<built-in function putenv>
>>> os.putenv == e.putenv
True

But 3.9 does not

Python 3.9.0 (default, Oct  7 2020, 23:09:01)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> e = os.environ
>>> e.putenv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '_Environ' object has no attribute 'putenv'

and definition of _Environ is also changed.

class _Environ(MutableMapping):
    def __init__(self, data, encodekey, decodekey, encodevalue, decodevalue):
        self.encodekey = encodekey
        self.decodekey = decodekey
        self.encodevalue = encodevalue
        self.decodevalue = decodevalue
        self._data = data
paddymccrudden commented 3 years ago

I would also be interested in having this resolved. I am hesitant to move to 3.9 until we can run our tests in parallel.

amal-khailtash commented 3 years ago

Making these changes works for Python 3.9+, but not sure if it breaks older releases 3.8-:

# pytest_parallel/__init__.py

114: class ThreadLocalEnviron(os._Environ):
115:     def __init__(self, env):
116:         super().__init__(
117:             env._data,
118:             env.encodekey,
119:             env.decodekey,
120:             env.encodevalue,
121:             env.decodevalue,
122:             # env.putenv,    # <---- Commented
123:             # env.unsetenv   # <---- Commented
124:         )

139:     def __setitem__(self, key, value):
140:         if key == 'PYTEST_CURRENT_TEST':
141:             value = self.encodevalue(value)
142:             os.putenv(self.encodekey(key), value)   # <------  Changed self to os

147:     def __delitem__(self, key):
148:         if key == 'PYTEST_CURRENT_TEST':
149:             os.unsetenv(self.encodekey(key))   # <------  Changed self to os
greatzt commented 3 years ago

I have got same issue. please fix it for 3.9

dankush commented 3 years ago

Also have the same issue

liuxu7411 commented 3 years ago

希望尽快支持3.9

Xorag commented 3 years ago

+1 hoping to see if the proposed PR can be merged

sanchos commented 3 years ago

The same issue

paddymccrudden commented 2 years ago

Would love this to be solved. It is preventing me from moving from 3.8. Is this closed as it is a pytest-parallel issue? I am guessing it is.

Sumedh-Kadoo commented 2 years ago

e solved. It is preventing me from moving from 3.8. Is this closed as it is a pytest-parall

Its happening with 3.9.7 so I read some of the issues here and it looks like this project is not maintained anymore.