pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Add deprecations for tests written for `nose` [SQUASH]

Open symonk opened this issue 3 years ago โ€ข 13 comments

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_setup etc.

symonk avatar May 01 '22 15:05 symonk

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...

The-Compiler avatar May 16 '22 08:05 The-Compiler

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.

nicoddemus avatar May 16 '22 11:05 nicoddemus

Moved to 7.2 milestone. ๐Ÿ‘

nicoddemus avatar Jun 14 '22 10:06 nicoddemus

Sorry folks, I will get this one wrapped up shortly

symonk avatar Jun 20 '22 15:06 symonk

@symonk gentle ping. ๐Ÿ˜

nicoddemus avatar Jul 31 '22 13:07 nicoddemus

@symonk gentle ping. grin

will get a look, thanks!

symonk avatar Aug 07 '22 16:08 symonk

้‚ฎไปถๅทฒๆ”ถๅˆฐ๏ผ

hwaking avatar Aug 07 '22 16:08 hwaking

@The-Compiler would appreciate a review if possible. ๐Ÿ‘

nicoddemus avatar Sep 15 '22 11:09 nicoddemus

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:

  1. 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).
  2. Make support for setup and teardown methods pytest native, outside nose.

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.

nicoddemus avatar Sep 15 '22 17:09 nicoddemus

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.

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/teardown function, 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).

Exirel avatar Sep 15 '22 21:09 Exirel

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?

nicoddemus avatar Sep 15 '22 23:09 nicoddemus

to support setup/teardown methods, 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. ๐Ÿ‘

Exirel avatar Sep 16 '22 08:09 Exirel

Thanks @Exirel for the feedback! ๐Ÿ‘

I updated my original post to make it clearer too.

nicoddemus avatar Sep 16 '22 11:09 nicoddemus

@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.

nicoddemus avatar Oct 09 '22 13:10 nicoddemus

The warning message now includes the text To remove this warning, rename it to '{method}_method(self) for plain setup/teardown methods.

nicoddemus avatar Oct 09 '22 13:10 nicoddemus

@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.

The-Compiler avatar Oct 09 '22 14:10 The-Compiler

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.

nicoddemus avatar Oct 09 '22 15:10 nicoddemus

Btw @The-Compiler could you give this another pass over? Thanks!

nicoddemus avatar Oct 09 '22 15:10 nicoddemus

Thanks @symonk and @The-Compiler!

nicoddemus avatar Oct 09 '22 20:10 nicoddemus