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

Show entire repr of fixture values #3693

Closed
dmtucker opened this issue Jul 18, 2018 · 8 comments
Closed

Show entire repr of fixture values #3693

dmtucker opened this issue Jul 18, 2018 · 8 comments
Labels
status: help wanted developers would like help from experts on this topic topic: fixtures anything involving fixtures directly or indirectly topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch

Comments

@dmtucker
Copy link

pytest 3.6.3 on Debian 9.5 (though, I'm running in Docker and can repro on CentOS 7)

This example from StackOverflow captures what I'd like to do:

================================================================= FAILURES =================================================================
____________________________________________________ test_check_default_content_for_user ___________________________________________________

test_data = {'amount_of_number_of_days_options': 6, 'available_for_guest': 'True', 'fl_password': 'password', 'fl_user': 'gg_abrestest@yahoo.com', ...}

When a test fails/errors, I want the full fixture value to be shown (i.e. no ...).
No combination of --tb long, -v, --full-trace, or --showlocals that I've tried has worked.
Is there a way to do this?

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1392 (Idea: make FixtureLookupError show prettier fixture list), #833 (--fixtures only shows fixtures from first file), #351 (Show repr() of exceptions passed to @parametrize), #2934 (capsysbinary fixture), and #3377 (Rescope a fixture).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jul 18, 2018
@RonnyPfannschmidt
Copy link
Member

i would suggest to pretty-print it yourself
this code is precisely in place to avoid massive objects destroying all sensible reading of the output (because after a certain size we have no way safely figure if it is still barely ok or not)

what could-be done is increasing the limit with verbosity however

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch type: question general question, might be closed after 2 weeks of inactivity and removed type: bug problem that needs to be addressed labels Jul 19, 2018
@dmtucker
Copy link
Author

what could-be done is increasing the limit with verbosity however

That would be greatly preferred as we have thousands of tests that would need revision otherwise.

@RonnyPfannschmidt RonnyPfannschmidt added the status: help wanted developers would like help from experts on this topic label Jul 19, 2018
@mgeier
Copy link

mgeier commented Nov 5, 2018

Is the threshold for shortening the repr with ... hard-coded somewhere in the PyTest code?

If yes, could this somehow be provided as option in pytest.ini or something like that?

@Zac-HD Zac-HD added topic: reporting related to terminal output and user-facing messages and errors topic: fixtures anything involving fixtures directly or indirectly and removed type: question general question, might be closed after 2 weeks of inactivity labels Dec 5, 2018
@dmtucker
Copy link
Author

Looks like this is the relevant code:

def _saferepr(self, obj):
return py.io.saferepr(obj)
def repr_args(self, entry):
if self.funcargs:
args = []
for argname, argvalue in entry.frame.getargs(var=True):
args.append((argname, self._saferepr(argvalue)))
return ReprFuncArgs(args)

py.io.saferepr is the call that does the shortening:
https://github.com/pytest-dev/py/blob/b9da2ed6178cd37d4ed6b41f9fa8234dce96973f/py/_io/saferepr.py#L53-L57

It takes a maxsize parameter; however, it only seems to allow tightening:

(Pdb) pp type(obj), len(obj)
(<class 'dict'>, 1000)
(Pdb) pp py.io.saferepr(obj)
'{0: 6009, 1: 6010, 2: 6011, 3: 6012, ...}'
(Pdb) pp py.io.saferepr(obj, maxsize=10)
'{0:......}'
(Pdb) pp py.io.saferepr(obj, maxsize=100)
'{0: 6017, 1: 6018, 2: 6019, 3: 6020, ...}'
(Pdb) pp py.io.saferepr(obj, maxsize=1000)
'{0: 6021, 1: 6022, 2: 6023, 3: 6024, ...}'
(Pdb) pp py.io.saferepr(obj, maxsize=10000)
'{0: 6025, 1: 6026, 2: 6027, 3: 6028, ...}'

@dmtucker
Copy link
Author

I think py.io.safrepr would need to set other Repr.max* attributes:
https://github.com/pytest-dev/py/blob/b9da2ed6178cd37d4ed6b41f9fa8234dce96973f/py/_io/saferepr.py#L68-L70

@blueyed
Copy link
Contributor

blueyed commented Oct 9, 2019

There's an internal "truncate_locals" option that gets used with -vv, and enables skipping of truncation with -l. Via #3681.

@blueyed blueyed closed this as completed Oct 9, 2019
@tucked
Copy link

tucked commented Nov 8, 2019

I'm still seeing this issue with Pytest 4.6.6 (looks like #3681 is in 3.7.0, so should be included)... Am I understanding correctly that I should only need to pass -vv -l?

edit: Oh wow, nevermind... The locals appear below the failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted developers would like help from experts on this topic topic: fixtures anything involving fixtures directly or indirectly topic: reporting related to terminal output and user-facing messages and errors type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

7 participants