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

assert failure inside doctest doesn't prettyprint #7

Closed
pytestbot opened this issue Nov 30, 2010 · 4 comments
Closed

assert failure inside doctest doesn't prettyprint #7

pytestbot opened this issue Nov 30, 2010 · 4 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: BitBucket: wtanksleyjr, GitHub: wtanksleyjr


Asserts inside doctests don't parse correctly; they instead produce an error that points to the wrong line. It looks like the backtrace is getting confused.

It may be possible to fix this specific error by finding a bug in our doctest code; but it may also be possible to handle the general case where the backtracking information doesn't lead into the test code. When that happens, it would be ideal to show an error message that points to the last line of test code run, even if the location isn't in the backtrace.

I've attached doc.py to demonstrate the assert problem.


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


fix issue7 - assert failure inside doctest doesn't prettyprint

unexpected exceptions are now reported within the doctest failure
representation context.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


actually you may install the fix with

pip install -i http://pypi.testrun.org -U pytest

(py.test --version should show 2.0.1.dev3).

Please open a new issue for the more general suggestion. I am not sure i understand it. Normally, when test source code fails and you see a traceback, you can scroll up a bit and see which line in the test function started it. This was obfuscated in the doctest reporting but should be fixed now. If an issue remains please open a new issue and provide an example if you can.

cheers, holger

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: wtanksleyjr, GitHub: wtanksleyjr:


I confirm that one of my suggestions in this bug is fixed. The test case I attached to my original report still says there's something wrong, since assert still doesn't prettyprint its results -- but at least the correct line number is deduced.
I'm good with leaving this one at "resolved" and opening a new one.

@pytestbot
Copy link
Contributor Author

Original comment by BitBucket: wtanksleyjr, GitHub: wtanksleyjr:


I'd like it if assert worked inside a doctest, but am I wasting my time? I can see that it might be very hard to make that work.

Doctest is very brittle, since it compares textual representations. Assert is robust, since it can use any method. py.test makes assert as informative as doctest... So the combination would be perfect.

But perhaps this is impossible -- doctest is different from py.test's assert, and perhaps they're incompatible, since doctest is supposed to catch and interpret assertions.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
blueyed added a commit that referenced this issue Oct 22, 2019
Before:

> FAILED foo/test.py::test_bar - Failed: Database access not allowed, …

After:

> FAILED foo/test.py::test_bar - Database access not allowed, …
mgorny pushed a commit to mgorny/pytest that referenced this issue May 27, 2023
fix: avoid errors when filename is too long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant