numirias / pytest-json-report

🗒️ A pytest plugin to report test results as JSON
MIT License
147 stars 39 forks source link

Pytest crashes when using json-report and xdist plugins together #52

Closed krizo closed 4 years ago

krizo commented 4 years ago

I am having an issue with pytest-json-report and pytest-xdist plugins working togehter. Basically, the tests run smoothly when started with these two separatley, so from functional point of view, seems like there is no issue.

The problem starts only when both are enabled. I am getting this after the nodes are being initialized (running with -n 2):

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/_pytest/main.py", line 196, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/_pytest/main.py", line 246, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/xdist/dsession.py", line 112, in pytest_runtestloop
INTERNALERROR>     self.loop_once()
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/xdist/dsession.py", line 135, in loop_once
INTERNALERROR>     call(**kwargs)
INTERNALERROR>   File "/path/to/test/root/.venv/lib/python3.7/site-packages/xdist/dsession.py", line 177, in worker_workerfinished
INTERNALERROR>     assert not crashitem, (crashitem, node)
INTERNALERROR> AssertionError: ('path_to_test/test_file.py::test_function[TestName]', <WorkerController gw1>)
INTERNALERROR> assert not 'path_to_test/test_file.py::test_function[TestName]'

It's difficult to find the troublemaker, since the stack trace is not complete.

I tried several things to get rid of it:

  1. Bumping xdist version (up and down)
  2. Same thing with json-report version
  3. Bumping pytest itself - also up and down
  4. Clearing out all custom hooks I overwritten (so basically plugins work as their defaults)
  5. Invoking json-report by cmd line switches or by putting it in pytest_configure
  6. Running on python 3.8.x
  7. Running on different OS.

My questions are:

  1. Did anybody have similar problems?
  2. How to debug it to get the clear root cause of the problem

And of course I would be grateful for other suggestions and ideas how to tackle this.

krizo commented 4 years ago

List of my current modules installed:

apipkg==1.5
appdirs==1.4.3
attrs==19.3.0
beautifulsoup4==4.8.2
certifi==2019.11.28
cffi==1.14.0
chardet==3.0.4
click==7.1.2
colorama==0.4.3
commonmark==0.9.1
cryptography==2.8
distlib==0.3.0
et-xmlfile==1.0.1
eulxml==1.1.3
execnet==1.7.1
factory-boy==2.12.0
fake-useragent==0.1.11
Faker==4.0.0
filelock==3.0.12
idna==2.8
importlib-metadata==1.5.0
iso4217==1.6.20180829
jdcal==1.4.1
json2html==1.3.0
json2table==1.1.5
lxml==4.5.0
makefun==1.9.2
mock==4.0.2
more-itertools==8.2.0
multidict==4.7.5
numpy==1.18.4
openpyxl==3.0.3
packaging==20.1
pandas==1.0.3
pdfkit==0.6.1
pluggy==0.13.1
ply==3.11
pprintpp==0.4.0
py==1.8.1
py-cpuinfo==5.0.0
pycparser==2.19
Pygments==2.6.1
pyodbc==4.0.30
pyOpenSSL==19.1.0
pyparsing==2.4.6
pytest==5.3.1
pytest-emoji==0.2.0
pytest-instafail==0.4.1.post0
pytest-json-report==1.2.1
pytest-metadata==1.9.0
pytest-nunit==0.5.3
pytest-parallel==0.1.0
pytest-pycharm==0.6.0
pytest-spec==2.0.0
pytest-steps==1.7.3
pytest-sugar==0.9.2
pytest-xdist==1.32.0
python-dateutil==2.8.1
pytz==2019.3
PyYAML==5.2
requests==2.22.0
requests-pkcs12==1.6
requests-toolbelt==0.9.1
rich==1.0.0
rstr==2.2.6
selenium==3.141.0
six==1.14.0
soupsieve==2.0
tblib==1.6.0
termcolor==1.1.0
text-unidecode==1.3
toml==0.10.0
tox==3.14.5
typing-extensions==3.7.4.2
Unidecode==1.1.1
urllib3==1.25.8
useragent==0.1.1
vcrpy==2.1.1
virtualenv==20.0.7
wcwidth==0.1.8
wrapt==1.12.0
xmltodict==0.12.0
yarl==1.4.2
zipp==3.0.0
krizo commented 4 years ago

Sorry, it turned out it's related to my custom logger, which for some reason couldn't be handled by the plugin.

clairexiayanping commented 1 year ago

Hi @krizo , I encountered the same problem. Could you tell me how you fix the above issue? Thanks. I use the logger 'logger = log.getLogger(name)' and def getLogger(name): logging_config = dict( version = 1, disable_existing_loggers = False, formatters = { 'f': {'format': '%(asctime)s %(process)d %(name)-12s %(levelname)-8s %(message)s'} }, handlers = { 'h': {'class': 'logging.StreamHandler', 'formatter': 'f', 'level': logging.INFO} }, root = { 'handlers': ['h'], 'level': logging.INFO, }, ) logging.config.dictConfig(logging_config) return logging.getLogger(name)

krizo commented 1 year ago

@clairexiayanping That was a long time ago... If you provide my mor e info what happens, maybe I will be able to recall.