Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--tb=line -> giving a trace back #7743

Closed
kevindawson opened this issue Sep 11, 2020 · 2 comments
Closed

--tb=line -> giving a trace back #7743

kevindawson opened this issue Sep 11, 2020 · 2 comments

Comments

@kevindawson
Copy link

kevindawson commented Sep 11, 2020

  • [x ] a detailed description of the bug or suggestion
    Whilst working my way through "Python Testing with pytest"

the issue is the use of --tb=line

  • [x ] output of pip list from the virtual environment you are using
(code) kevin@donkey:~/SandBox/code/ch4/cache$ pip list
Package           Version Location
----------------- ------- ---------------------------------------
astroid           2.4.2
atomicwrites      1.4.0
attrs             20.2.0
click             7.1.2
colorama          0.4.3
coverage          5.2.1
crayons           0.4.0
Cython            0.29.21
icdiff            1.9.1
iniconfig         1.0.1
isort             5.4.2
lazy-object-proxy 1.4.3
mccabe            0.6.1
mongo             0.2.0
more-itertools    8.5.0
packaging         20.4
pip               20.2.2
pluggy            0.13.1
pprintpp          0.4.0
py                1.9.0
pylint            2.6.0
pymongo           3.11.0
pyparsing         2.4.7
pytest            6.0.1
pytest-cov        2.10.1
pytest-icdiff     0.5
pytest-mock       3.3.1
setuptools        49.2.0
six               1.15.0
tasks             0.1.0   /home/kevin/SandBox/code/tasks_proj/src
tinydb            4.1.1
toml              0.10.1
wheel             0.34.2
wrapt             1.12.1

  • [x ] pytest and operating system versions
pytest 6.0.1
Python 3.8.2
Linux donkey 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  • [x ] minimal example if possible
    test_slower.py
import datetime
import pytest
import random
import time


@pytest.fixture(autouse=True)
def check_duration(request, cache):
    key = "duration/" + request.node.nodeid.replace(":", "_")
    # nodeid's can have colons
    # keys become filenames within .cache
    # replace colons with something filename safe
    start_time = datetime.datetime.now()
    yield
    stop_time = datetime.datetime.now()
    this_duration = (stop_time - start_time).total_seconds()
    last_duration = cache.get(key, None)
    cache.set(key, this_duration)
    if last_duration is not None:
        errorstring = "test duration over 2x last duration"
        assert this_duration <= last_duration * 2, errorstring


@pytest.mark.parametrize("i", range(5))
def test_slow_stuff(i):
    time.sleep(random.random())

Output

(code) kevin@donkey:~/SandBox/code/ch4/cache$ pytest -q --tb=line test_slower.py
....E.                                                                                                                                                            [100%]
================================================================================ ERRORS =================================================================================
________________________________________________________________ ERROR at teardown of test_slow_stuff[3] ________________________________________________________________
Traceback (most recent call last):
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/config/__init__.py", line 180, in console_main
    code = main()
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/config/__init__.py", line 157, in main
    ret = config.hook.pytest_cmdline_main(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/main.py", line 289, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/main.py", line 277, in wrap_session
    config.hook.pytest_sessionfinish(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/terminal.py", line 813, in pytest_sessionfinish
    self.config.hook.pytest_terminal_summary(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/pluggy/callers.py", line 182, in _multicall
    next(gen)  # first yield
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/terminal.py", line 827, in pytest_terminal_summary
    self.summary_errors()
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/terminal.py", line 1032, in summary_errors
    self._outrep_summary(rep)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/terminal.py", line 1035, in _outrep_summary
    rep.toterminal(self._tw)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/reports.py", line 82, in toterminal
    longrepr.toterminal(out)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/_code/code.py", line 951, in toterminal
    element[0].toterminal(tw)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/_code/code.py", line 981, in toterminal
    entry.toterminal(tw)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/_code/code.py", line 1079, in toterminal
    self._write_entry_lines(tw)
  File "/home/kevin/.local/share/virtualenvs/code-PeIGB9Qw/lib/python3.8/site-packages/_pytest/_code/code.py", line 1048, in _write_entry_lines
    assert not seeing_failures, (
AssertionError: Unexpected failure lines between source lines:
E   AssertionError: test duration over 2x last duration
    assert 0.635612 <= (0.095207 * 2)
(code) kevin@donkey:~/SandBox/code/ch4/cache$ 

dodo-x hope this will suffice ;)

@nicoddemus
Copy link
Member

nicoddemus commented Sep 11, 2020

Thanks @kevindawson for the report! This has been fixed by #7707 and should be out in 6.0.2 soon. 👍

@kevindawson
Copy link
Author

thanks for the heads up @nicoddemus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants