Skip to content
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

Add initial support for pytest plugins #18217

Closed
wants to merge 3 commits into from

Conversation

pranavrajpal
Copy link

This adds initial support for pytest plugin-generated tests, including running and debugging tests, and opening tests in the editor (even if the location is a non-Python file).

Debugging non-Python files still isn't supported.

This PR has the consequence of making nodeids not always be unique, because a plugin could always generate multiple tests with the same name in the same suite. Most of the code seems to assume that they will be unique, though, because the UI only shows only one test even when multiple tests have the same nodeid.

I don't know what the ideal solution for that is, because the current behavior has some strange consequences when interacting with tests with repeated nodeids, but repeating nodeids seems like a bug considering that the pytest docs say that nodeids are supposed to be unique:

Each collected test is assigned a unique nodeid

Work on #16742 and #16852
Both of those tests mention crashes with specific plugins, but I haven't tested any of those plugins so I don't know if those crashes are fixed.

Instead of completely ignoring plugin-generated tests, handle
plugin-generated tests that are instances of `pytest.Item`.
Add a test to make sure we handle plugin-generated tests correctly.
There are a couple of things this tries to test that (can) happen in
plugin-generated tests:
- an instance of pytest.Item that isn't one of the classes that gets
  special cased
- a test location that's different from the file that the test was
  created
- a suite name with dots in it
- an expected output path that doesn't have a dotted path to a function
Each SingleTestInfo instance is created with the default value of kind,
which is "function", even when that should really be "doctest" or, as of
this PR, "other".
@ghost
Copy link

ghost commented Dec 23, 2021

CLA assistant check
All CLA requirements met.

@kimadeline
Copy link

Hi @pranavrajpal, thank you for your PR!

We are in the process of revamping test discovery for both pytest and unittest (#17242, January iteration plan at #18214), and we are going to replace the code being modified in this PR soon.

Even though I am closing this PR, thank you for bringing this use case to our attention, we'll make sure to cover it in the testing rewrite 🙂

@kimadeline kimadeline closed this Jan 4, 2022
@pranavrajpal
Copy link
Author

@kimadeline Would it be possible to reconsider reviewing this PR? Work on #17242 seems to have stalled (or at the very least I can't find any reference to PRs refactoring or rewriting the pytest adapter) and this is a relatively simple but still useful change, even if it will get replaced soon.

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 this pull request may close these issues.

2 participants