freakboy3742 / pytest-tldr Goto Github PK
View Code? Open in Web Editor NEWA pytest plugin that limits the output to just the things you need.
License: BSD 3-Clause "New" or "Revised" License
A pytest plugin that limits the output to just the things you need.
License: BSD 3-Clause "New" or "Revised" License
I'm not sure if this is a bug in pytest-json
or pytest-tldr
:
Traceback (most recent call last):
File ".../bin/pytest", line 11, in <module>
sys.exit(main())
File ".../lib/python3.7/site-packages/_pytest/config/__init__.py", line 64, in main
return config.hook.pytest_cmdline_main(config=config)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File ".../lib/python3.7/site-packages/_pytest/main.py", line 208, in pytest_cmdline_main
return wrap_session(config, _main)
File ".../lib/python3.7/site-packages/_pytest/main.py", line 178, in wrap_session
session.exitstatus = doit(config, session) or 0
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
return outcome.get_result()
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File ".../lib/python3.7/site-packages/pytest_tldr.py", line 282, in pytest_sessionfinish
terminalreporter=self, exitstatus=exitstatus
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File ".../lib/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
return outcome.get_result()
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File ".../lib/python3.7/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File ".../lib/python3.7/site-packages/pytest_jsonreport/plugin.py", line 136, in pytest_terminal_summary
terminalreporter.write_sep('-', 'JSON report')
AttributeError: 'TLDRReporter' object has no attribute 'write_sep'
I get the following error after installing:
$ pytest
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/_pytest/main.py", line 174, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/_pytest/config.py", line 957, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/__init__.py", line 628, in call_historic
INTERNALERROR> res = self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR> firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pytest_tldr.py", line 17, in pytest_configure
INTERNALERROR> reporter = TLDRReporter(config, sys.stdout)
INTERNALERROR> File "/Users/poswald/Projects/myproj/env/lib/python3.6/site-packages/pytest_tldr.py", line 45, in __init__
INTERNALERROR> self.xdist = self.config.option.numprocesses is not None
INTERNALERROR> AttributeError: 'Namespace' object has no attribute 'numprocesses'
$ pip freeze |grep pytest
pytest==3.6.1
pytest-runner==2.11.1
pytest-tldr==0.1.1
$ python --version
Python 3.6.5
Installing pytest-xdist
fixes it.
I tried out using pytest-tldr on Python 3.7 and it worked, but produced an odd warning:
/usr/local/lib/python3.7/site-packages/pytest_tldr.py:282: UserWarning: Argument(s) ('config',) which are declared in the hookspec can not be found in this hook call terminalreporter=self, exitstatus=exitstatus
Is this a bug?
When there is an error in Test Collections such as SyntaxError
, it would be nice to be reminded of that.
Basically, shows
----------------------------------------------------------------------
Ran 0 tests
OK
when running pytest with syntax error code such as print 'hello'
in python3.
With pytest-tldr==0.2.2 and pytest==6.0.1, I'm seeing behaviour that turns up no output in the terminal at all, until either the tests are completed or I abort the test process โ then, all collected output is printed at once. (FWIW, this doesn't happen with pytest-sugar)
Hi, I'm having a bit of trouble using the tool.
When I try to run the pytest_web_ui like so: 'python3 -m pytest_web_ui {path_to_my_project_folder}'
I get an error message: Failed to collect tests from {path_to_my_project_folder}/conftest.py
I can't figure out why it's searching in conftest.py for tests.
The project contains 6 tests in a file named test_program not in a class.
I have no idea why this happens.. Any help will be very much appreciated. Thanks in advance.
Hi there,
This is a great plugin! Is there a way to either enable the plugin with a flag (e.g. pytest --tldr
) or alternatively disable it with a flag (e.g. pytest --no-tldr
) while it is installed?
It would be nice to have the option to look at the TLDR output during test development, and complete (e.g. native pytest, or even pytest-sugar
or pytest-cov
) output in other cases such as in a CI dashboard, as sometimes the additional context there in the default/sugared output is helpful.
Ideally in order to play nicely with other plugins that may be installed, it would be great if config could be specified in setup.cfg
to indicate whether TLDR should be enabled or disabled in a default pytest
invocation, and then the flags --tldr
and --no-tldr
could toggle it at runtime, depending on the default value.
Failing CI for beeware/briefcase#943 is suggesting pytest-tldr
needs updates to continue working with pytest>=7.2.0
.
11s
Run tox -e py --installpkg dist/*.whl
tox -e py --installpkg dist/*.whl
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
env:
python_version: 3.9
pythonLocation: /opt/hostedtoolcache/Python/3.[1](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:1)0.8/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.10.8/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.8/x64
Python[2](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:2)_ROOT_DIR: /opt/hostedtoolcache/Python/[3](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:3).10.8/x6[4](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:4)
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.10.8/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.8/x64/lib
py create: /home/runner/work/briefcase/briefcase/.tox/py
py inst: /home/runner/work/briefcase/briefcase/.tox/.tmp/package/1/briefcase-0.3.12.dev[5](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:5)1+gd4888321-py3-none-any.whl
py installed: arrow==1.2.3,attrs==22.1.0,binaryornot==0.4.4,briefcase @ file:///home/runner/work/briefcase/briefcase/.tox/.tmp/package/1/briefcase-0.3.12.dev51%2Bgd4888321-py3-none-any.whl,certifi==2022.9.24,chardet==5.0.0,charset-normalizer==2.1.1,click==8.1.3,commonmark==0.9.1,cookiecutter==2.1.1,coverage==[6](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:6).5.0,exceptiongroup==1.0.0rc9,gitdb==4.0.9,GitPython==3.1.29,idna==3.4,iniconfig==1.1.1,Jinja2==3.1.2,jinja2-time==0.2.0,MarkupSafe==2.1.1,packaging==21.3,platformdirs==2.5.2,pluggy==1.0.0,psutil==5.9.3,Pygments==2.13.0,pyparsing==3.0.9,pytest==[7](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:7).2.0,pytest-cov==4.0.0,pytest-tldr==0.2.4,python-dateutil==2.[8](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:8).2,python-slugify==6.1.2,PyYAML==6.0,requests==2.28.1,rich==12.6.0,six==1.16.0,smmap==5.0.0,text-unidecode==1.3,tomli==2.0.1,tomli_w==1.0.0,urllib3==1.26.12
py run-test-pre: PYTHONHASHSEED='420284[9](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:9)385'
py run-test: commands[0] | python -m coverage run -m pytest -vv
platform linux -- Python 3.[10](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:10).8
pytest==7.2.0
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
INTERNALERROR> return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/runner/work/briefcase/briefcase/.tox/py/lib/python3.10/site-packages/pytest_tldr.py", line [15](https://github.com/beeware/briefcase/actions/runs/3324020664/jobs/5495092973#step:6:16)5, in pytest_sessionstart
INTERNALERROR> self.print("py=={}".format(py.__version__))
INTERNALERROR> AttributeError: module 'py' has no attribute '__version__'
ERROR: InvocationError for command /home/runner/work/briefcase/briefcase/.tox/py/bin/python -m coverage run -m pytest -vv (exited with code 3)
___________________________________ summary ____________________________________
ERROR: py: commands failed
Error: Process completed with exit code 1.
This seems like the likely source (from 7.2.0 release notes):
pytest-dev/pytest#10396: pytest no longer depends on the py library. pytest provides a vendored copy of py.error and py.path modules but will use the py library if it is installed. If you need other py.* modules, continue to install the deprecated py library separately, otherwise it can usually be removed as a dependency.
When running with Python 2.7.15 I get:
$ pytest
Traceback (most recent call last):
File "/home/daonb/src/matific/SlateMathWeb/env/bin/pytest", line 11, in <module>
sys.exit(main())
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/config.py", line 52, in main
config = _prepareconfig(args, plugins)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/config.py", line 163, in _prepareconfig
pluginmanager=pluginmanager, args=args)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/callers.py", line 196, in _multicall
gen.send(outcome)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/helpconfig.py", line 68, in pytest_cmdline_parse
config = outcome.get_result()
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/callers.py", line 77, in get_result
_reraise(*ex) # noqa
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/config.py", line 936, in pytest_cmdline_parse
self.parse(args)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/config.py", line 1086, in parse
self._preparse(args, addopts=addopts)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/_pytest/config.py", line 1048, in _preparse
self.pluginmanager.load_setuptools_entrypoints('pytest11')
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pluggy/__init__.py", line 397, in load_setuptools_entrypoints
plugin = ep.load()
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2318, in load
return self.resolve()
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2324, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/daonb/src/matific/SlateMathWeb/env/local/lib/python2.7/site-packages/pytest_tldr.py", line 55
def print(self, *args, **kwargs):
^
SyntaxError: invalid syntax
$ pip freeze | grep pytest
pytest==3.5.0
pytest-django==3.1.2
pytest-forked==0.2
pytest-tldr==0.1.1
pytest-watch==4.1.0
pytest-xdist==1.21.0
Hello! My team loves pytest-tldr, but we recently ran into some issues where diff truncation in the non-verbose output of pytest was interfering with debugging flaky tests. We want a way to have the tldr functionality, but have verbose output for fail/error/unexpected pass reports.
I was able to get this functionality by ripping out the "verbosity" sensitivity from pytest-tldr all together, and then running pytest in verbose mode. The blunt force version is forked on my github account.
If I were to clean this up (read: restore original functionality and make it configurable) would you consider accepting a PR to add this mode?
Thanks for your work!
It would be nice if this would produce pytest-cov report as well.
I am not getting the profile table at the end of the tests.
$ pip install pytest==5.4.3
$ pip install pytest-tldr
$ echo "def test_foo():
asssert True
" > tests.py
$ pytest
Traceback (most recent call last):
File "/home/blaxter/.virtualenvs/test/bin/pytest", line 8, in <module>
sys.exit(main())
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/_pytest/config/__init__.py", line 124, in main
ret = config.hook.pytest_cmdline_main(
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/_pytest/main.py", line 240, in pytest_cmdline_main
return wrap_session(config, _main)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/_pytest/main.py", line 228, in wrap_session
config.hook.pytest_sessionfinish(
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
return outcome.get_result()
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pytest_tldr.py", line 277, in pytest_sessionfinish
self.print()
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/pytest_tldr.py", line 119, in print
self._tw.write(end, flush=flush)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/py/_io/terminalwriter.py", line 253, in write
markupmsg = self.markup(msg, **kw)
File "/home/blaxter/.virtualenvs/test/lib/python3.8/site-packages/py/_io/terminalwriter.py", line 209, in markup
raise ValueError("unknown markup: %r" %(name,))
ValueError: unknown markup: 'flush'
due to https://github.com/freakboy3742/pytest-tldr/blob/master/pytest_tldr.py#L303
we received pytest-dev/pytest#7626
i believe the best solution to prevent that in future is to either use longreprtext
instead of longrepr
for printing or to use totermainal
where applicable
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.