Skip to content

Exclude some test modules from assertion rewriting #2203

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
nicoddemus opened this issue Jan 17, 2017 · 8 comments
Closed

Exclude some test modules from assertion rewriting #2203

nicoddemus opened this issue Jan 17, 2017 · 8 comments
Labels
type: feature-branch new feature or API change, should be merged into features branch

Comments

@nicoddemus
Copy link
Member

Sometimes users do some "black magic" like patching builtins (for example #2180) and that might completely break pytest.

While of course we should not encourage too much black magic, I was wondering if we could alleviate the problem for users which don't want or can't change their tests to disable assertion rewriting for some of the test modules.

I was thinking of something like the # encoding comment used by Python to declare the encoding of a file. An alternative would be to list some test files on pytest.ini, but I think the comment is better because it is written in the file itself, rather than far away from it.

How about # pytest-no-rewrite or something like this?

@nicoddemus nicoddemus added the type: feature-branch new feature or API change, should be merged into features branch label Jan 17, 2017
@The-Compiler
Copy link
Member

I don't think this would help with #2180 though, would it? I suppose we'd still need to use open() to read the comment 😉

@nicoddemus
Copy link
Member Author

@The-Compiler you're right. 😁

@nicoddemus
Copy link
Member Author

From #743, there's an undocumented PYTEST_DONT_REWRITE in place already, perhaps we are halfway there already (save builtin open(), skip bytecode rewriting, docs, etc).

@jacebrowning
Copy link

PYTEST_DONT_REWRITE is exactly what I needed. Any chance we could get this formally documented?

My use case is a pytest plugin that manages its own assertion messages: https://github.com/jacebrowning/pytest-expecter

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 19, 2017
@nicoddemus
Copy link
Member Author

Any chance we could get this formally documented?

FWIW this is now on the reference page. 😉

@laike9m
Copy link

laike9m commented Apr 5, 2020

Would be cool if there's a flag to always disable rewrite.

@blueyed
Copy link
Contributor

blueyed commented Apr 5, 2020

@laike9m
--rewrite=plain?
You can use this in a config via addopts.

@laike9m
Copy link

laike9m commented Apr 5, 2020

Ah interesting. Found that in the documentation. Thanks!

https://docs.pytest.org/en/latest/assert.html#disabling-assert-rewriting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature-branch new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

5 participants