pytest
pytest copied to clipboard
Add deprecations for tests written for `nose` [SQUASH]
Adds deprecation warnings for tests written in nose, namely around setup and teardown aspects; as we support limited functionality.
I went with a pytest 8.x deprecation as I think that is the norm here. I also notice a few things when reviewing docs locally:
~my version was showing 6.3.x-dev*~ was my fault;
tox -e docs does not work in python 3.10+ due to an upstream issue in sphinx/util/typing.py we may need a version bump there? I will chase that up in a second
closes #9886
Todo:
- Implement a solution for
call_optional(...) - Investigate the mention of
@with_setupetc.
Does this only affect @with_setup, or also undecorated plain setup and teardown methods on test classes? The latter is technically part of our nose support, but as far as I'm aware, there are many projects using them with pytest-style tests without being aware that they are supposed to be nose specific...
there are many projects using them with pytest-style tests without being aware that they are supposed to be nose specific...
Good point. In that case they will get a warning, and we should mention in the deprecation docs how to port it to use something pytest-native.
Moved to 7.2 milestone. ๐
Sorry folks, I will get this one wrapped up shortly
@symonk gentle ping. ๐
@symonk gentle ping. grin
will get a look, thanks!
้ฎไปถๅทฒๆถๅฐ๏ผ
@The-Compiler would appreciate a review if possible. ๐
edit: The more I look at it, the more I seem to see genuine cases of this being used in numpy, celery, ceph, and similar high-profile projects...
I see, thanks for looking into it.
I strongly believe we should deprecate nose, but given that people have been using setup and teardown for methods thinking this was part of the pytest core feature set, we have a few options:
- Go ahead with the deprecation: to be fair it is a simple find/replace, and is backward-compatible with very old pytest versions (ancient versions even).
- Make support for
setupandteardownmethods pytest native, outsidenose.
Implementing 2) should be trivial, we already support setup_method and teardown_method named-methods, so it should be just a matter of extending that to setup and teardown names.
Implementing 2) should be trivial, we already support
setup_methodandteardown_methodnamed-methods, so it should be just a matter of extending that tosetupandteardownnames.
Hi! Sopel dev here, and here is our story. For the next major release of our IRC Bot, we try to support Python 3.10 and the latest version of pytest. When working on that, we discovered an issue with our test suite: for some unknown reason at the time, pytest would suddenly think that our setup function was now a test hook function. That was very unfortunate for a moment.
We were very happy when we understood the problem, and the solution: we deactivated the nose plugin, and all our problems went away.
So, from our perspective, we are fine with the following options:
- remove the nose plugin from pytest
- keep the plugin, but make sure we can deactivate it
- officially support
setup/teardownfunction, but making sure it is configurable (opt-out, opt-in, regex pattern, etc.)
Basically: we really need to make sure we can still run pytest without having to change our codebase, or our user's codebase, to accommodate for something that was not, as far as I know, officially documented (at least until now).
officially support setup/teardown function, but making sure it is configurable (opt-out, opt-in, regex pattern, etc.)
Just to make it clear, my proposal is to support setup/teardown methods, not functions. IIUC that would not affect your test suite, right?
to support
setup/teardownmethods, not functions.
Oh! You're right, I was worried about functions, not methods. In that case, and since pytest has a configuration for class naming convention, we would not have any problem with that. Thanks for the clarification. ๐
Thanks @Exirel for the feedback! ๐
I updated my original post to make it clearer too.
@The-Compiler what do you think regarding https://github.com/pytest-dev/pytest/pull/9907#issuecomment-1248388970?
I'm leaning towards 1), mostly because we are showing a deprecation, and the fix is trivial by doing a simple find/replace.
The warning message now includes the text To remove this warning, rename it to '{method}_method(self) for plain setup/teardown methods.
@The-Compiler what do you think regarding #9907 (comment)?
I'm leaning towards 1), mostly because we are showing a deprecation, and the fix is trivial by doing a simple find/replace.
Seems fine to me, though I see one problem: Once the deprecation period is over, it turns into a silent failure, depending on what the user does in those methods.
Seems fine to me, though I see one problem: Once the deprecation period is over, it turns into a silent failure, depending on what the user does in those methods.
Yeah I agree it is not perfect, unfortunately.
We should make a point to add a big note to the release notes when we drop the functionality, I think is the best we can do.
Btw @The-Compiler could you give this another pass over? Thanks!
Thanks @symonk and @The-Compiler!