Skip to content

Conversation

@symonk
Copy link
Member

@symonk symonk commented Oct 25, 2020

Hi team, hope you are all keeping well. While trying to advance my knowledge of the project I have been understanding plugins a little bit. Here is a small PR to tidy up some of the stepwise plugin code for consistency. Some of the most important changes are:

  • Stop registering the plugin if stepwise itself is not active (rather than these constant is_active checks inside hooks).
  • Adding a --sw-skip shorthand option to mirror that of --sw itself
  • Added a pytest_sessionfinish hook to stepwise (this is because --cache-clear was always outputting the [] now, I wanted to keep --cache-clear accurate in such circumstances and claim the cache is 'empty' ? However (imo) this should be handled in pytest_unconfigure and when --sw is not present, stepwise is always writing the [] upfront. - need advice here

I moved some strings out into more constants/globals - curious on your thoughts on that & secondly I think we are permitted f string use now (that 3.5+ is no longer officially supported? - I think that is the case anyway).

closes #7938

As always - thanks for all the great contributions to this open source project everyone! I appreciate your own time to review this and welcome any feedback.

@symonk symonk marked this pull request as ready for review October 25, 2020 11:19
@symonk symonk requested a review from nicoddemus October 25, 2020 11:54
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @symonk.

👍 on the --sw-skip shorthand from me.

Regarding the plugin registration change, I think the is_active stuff was done in order to encapsulate the

            # Clear the list of failing tests if the plugin is not active.
            self.config.cache.set("cache/stepwise", [])

part of the plugin inside the plugin. Even though the is_active checks are ugly, I think it does make sense to keep it encapsulated. This way the plugin can be understood on its own, without having to know about the external hook which changes it.

@symonk
Copy link
Member Author

symonk commented Oct 25, 2020

Thanks @symonk.

👍 on the --sw-skip shorthand from me.

Regarding the plugin registration change, I think the is_active stuff was done in order to encapsulate the

            # Clear the list of failing tests if the plugin is not active.
            self.config.cache.set("cache/stepwise", [])

part of the plugin inside the plugin. Even though the is_active checks are ugly, I think it does make sense to keep it encapsulated. This way the plugin can be understood on its own, without having to know about the external hook which changes it.

Thanks @symonk.

👍 on the --sw-skip shorthand from me.

Regarding the plugin registration change, I think the is_active stuff was done in order to encapsulate the

            # Clear the list of failing tests if the plugin is not active.
            self.config.cache.set("cache/stepwise", [])

part of the plugin inside the plugin. Even though the is_active checks are ugly, I think it does make sense to keep it encapsulated. This way the plugin can be understood on its own, without having to know about the external hook which changes it.

I see, it feels a bit weird to register a plugin that is going to perform next to no work except setting stepwise in cache to [], would it not be a (albeit it negligible) performance benefit to avoid doing so under certain circumstances? Save us a few hookimpl invocations etc needlessly, that said I'm still infantly learning how the plugin system works so I will defer to your knowledge on this one

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it not be a (albeit it negligible) performance benefit to avoid doing so under certain circumstances? Save us a few hookimpl invocations etc needlessly

Yes, definitely. In particular the pytest_runtest_logreport can be called quite a lot (3 times per test) and reducing the number of hook calls of it is beneficial.


Looking again, now in my editor, since the entire file if dedicated to just the one plugin, there is not much risk of missing out what's going on as I feared in my comment. And if you keep the comment "# Clear the list of failing tests if the plugin is not active." then it even makes more sense. So I'm good with that part too.

@symonk
Copy link
Member Author

symonk commented Oct 26, 2020

@bluetech thanks for the feedback will address this one after work today

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, good work @symonk!

I've left a few comments, take a look and let me know what you think. 👍

@symonk symonk requested review from bluetech and nicoddemus October 27, 2020 18:51
config.hook.pytest_deselected(items=already_passed)
self.report_status = f"skipping {failed_index} already passed items."
items[:] = items[failed_index:]
config.hook.pytest_deselected(items=items[:failed_index])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, items at this point only contains the failed item and the other items after it (see my suggestion).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm that no tests caught this is troubling actually, most likely because this only affects the output summary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops my bad, will also add coverage there - yes very troubling :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicoddemus I (hope) my latest commit can cover this scenario, tho if you could have a look that would be appreciated. I plan as a follow up (subsequent ticket/PR) to move away from testdir here and use pytester instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@symonk If you want to test this, you can add a pytest_deselected hookimpl in a conftest.py file in the test, and check that it receives what is expected.

@symonk symonk requested a review from nicoddemus October 27, 2020 20:24
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @symonk, great work!

(We should squash the changes during merge)

@symonk
Copy link
Member Author

symonk commented Oct 28, 2020

Thanks, @bluetech are you happy with this now? (unable to squash-merge w/o reviews)

@symonk
Copy link
Member Author

symonk commented Oct 29, 2020

Thanks @bluetech

@symonk symonk requested a review from bluetech October 29, 2020 13:46
@bluetech
Copy link
Member

The ubuntu-pypy3 CI failure unfortunately looks legitimate.

@symonk
Copy link
Member Author

symonk commented Oct 29, 2020

damnit haha, will get to it shortly

@symonk
Copy link
Member Author

symonk commented Oct 29, 2020

@bluetech, @nicoddemus I can only assume the ubuntu-pypy3 is flaky? as it passed this time round :/

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can only assume the ubuntu-pypy3 is flaky? as it passed this time round :/

Since the failure happened in a relevant test, I suspect it is not flaky. But I suggest we merge and see if it recurs. If it does recur, and we don't find the cause, we might need to revert...

@symonk
Copy link
Member Author

symonk commented Oct 30, 2020

ok sounds good, il squash merge and keep an eye on it in other PRs regarding these tests

@symonk symonk merged commit 6cddeb8 into pytest-dev:master Oct 30, 2020
@symonk symonk deleted the stepwise-plugin-improvements branch October 30, 2020 19:13
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.

[Feature] Allow a --sw-skip shorthand cli arg like --sw itself permits

3 participants