Skip to content

Collect marked functions regardless of naming #6239

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
iwanb opened this issue Nov 20, 2019 · 5 comments
Closed

Collect marked functions regardless of naming #6239

iwanb opened this issue Nov 20, 2019 · 5 comments
Labels
type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@iwanb
Copy link
Contributor

iwanb commented Nov 20, 2019

This is just a suggestion, could a function/class be collected if it has a marker attached to it, even if it doesn't follow the function name filter?
I.e. add a ismarkedfunction, similar to the isnosetest, here and in istestclass:
https://github.com/pytest-dev/pytest/blob/master/src/_pytest/python.py#L315

Alternative implementations:

  • Change those istestfunction and istestclass methods into a pytest hook instead, so plugins can implement it
  • Have a specific marker which would trigger this behavior instead of any marker (that can also be implemented using the hook)
@nicoddemus
Copy link
Member

Hi @iwanb,

Thanks for the suggestion!

Personally I'm reluctant to add an alternative to test function collection that differs from what is common practice for years in pytest (and unittest).

Do you have a good use case where the name convention is not good enough?

@iwanb
Copy link
Contributor Author

iwanb commented Nov 20, 2019

It's mainly to avoid duplicating the "test_" (or other) prefix all over the place, which increases the length of the test IDs.

In our case we already use a marker on pretty much all tests to add some metadata, so it's already clear that it's a test case. So I want to implement the third option in a plugin, but it's cumbersome to do currently.

Thinking it over, the second and/or third option is probably the safest, as otherwise the automatic marking of testcases using a module-level pytestmark would have a weird behavior.

Right now I'll probably just monkeypatch the istestfunction method.

@nicoddemus
Copy link
Member

In our case we already use a marker on pretty much all tests to add some metadata, so it's already clear that it's a test case. So I want to implement the third option in a plugin, but it's cumbersome to do currently.

I see, thanks for the explanation.

I'm not against adding some hook which would allow this to be customized in a plugin, I still would rather not add an alternative to the pytest core for the above reasons though.

@Zac-HD Zac-HD added the type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature label Nov 20, 2019
@iwanb
Copy link
Contributor Author

iwanb commented Nov 20, 2019

Ok, I'll make a PR for the hook.

@blueyed blueyed closed this as completed Nov 27, 2019
@blueyed blueyed reopened this Nov 27, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Jul 6, 2024

Closing this as stale; I'd still accept a PR for the hook but I don't think we want it so much as to keep an issue around (cf #12465)

@Zac-HD Zac-HD closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

4 participants