Skip to content

documentation: still no assertion introspection if assertion has message? #11265

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

Closed
calestyo opened this issue Jul 31, 2023 · 2 comments · Fixed by #11285
Closed

documentation: still no assertion introspection if assertion has message? #11265

calestyo opened this issue Jul 31, 2023 · 2 comments · Fixed by #11285

Comments

@calestyo
Copy link
Contributor

Hey.

Sorry if I miss something obvious and just make noise... O:-)

https://docs.pytest.org/en/7.4.x/how-to/assert.html claims:

However, if you specify a message with the assertion like this:
assert a % 2 == 0, "value was odd, should be even"
then no assertion introspection takes places at all and the message will be simply shown in the traceback.

But when I try this, then introspection does seem to happen i.e. I see e.g.:

>       assert len(pathname) <= len(escaped_pathname), "foobar"
E       AssertionError: foobar
E       assert 2 <= 1
E        +  where 2 = len('//')
E        +  and   1 = len('/')

test_misc.py:48: AssertionError

just with the additional message.

Could it be that this has changed at some point in time but documentation wasn't updated?

Thanks,
Chris.

@The-Compiler
Copy link
Member

That part of the docs is from 2011 (29d58ff, 8de5034).

It looks like support for assert introspection was added in 2014: 37bd1e0 - also see #549.

So yep, it looks like this is indeed just outdated! Would you like to open a PR removing that sentence?

calestyo added a commit to calestyo/pytest that referenced this issue Aug 5, 2023
It was pointed out[0] that the previous behaviour has been obsoleted by
commit 37bd1e0.

[0] pytest-dev#11265 (comment)

Signed-off-by: Christoph Anton Mitterer <[email protected]>
@calestyo
Copy link
Contributor Author

calestyo commented Aug 5, 2023

@The-Compiler I didn't remove the sentence but merely replace it with the information that the message is printed, too.

Think it's actually valuable to know that, thus better than removing.

The-Compiler pushed a commit that referenced this issue Aug 5, 2023
It was pointed out[0] that the previous behaviour has been obsoleted by
commit 37bd1e0.

[0] #11265 (comment)

Signed-off-by: Christoph Anton Mitterer <[email protected]>
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

Successfully merging a pull request may close this issue.

2 participants