-
- Notifications
You must be signed in to change notification settings - Fork 33.3k
bpo-32972: Unittest: Add a runTestMethod to TestCase (don't merge) #6051
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
Conversation
This allows a future subclass to customize how the test method is run. For example, this is required in order to create an "AsyncTestCase" that runs coroutines in an event loop.
Lib/unittest/case.py Outdated
| msg = self._formatMessage(msg, standardMsg) | ||
| raise self.failureException(msg) | ||
| | ||
| def _runTestMethod(self, method): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is documented as something that can be overloaded in subclasses, I think it should be a public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Should it be publicly documented (in unittest.rst) as well?
| Sure, the Another question is P.S. |
| Added |
| I am not sure we need As for the name, I have no opinion either way. doTest sounds good to me. Happy to change it unless anyone objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR looks good, but there's still an open issue: setUp and tearDown shouldn't be async, but we still need a way to have their asyncTearDown and asyncSetUp equivalents.
| A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
| Since setUp and tearDown shouldn't be async, I am nore sure that there is much left to do in TestCase at this point. I was thinking that asyncSetup and asyncTearDown can be implemented in the subclass using setUp and tearDown without any special support in TestCase. That way, we don't have to increase the public API of TestCase that much. I believe that we can implement an AsyncTestCase with what we have in this PR. |
| People assume that That's why I propose an alternative: let's support |
| Yes, that would work, but having both setUp and doSetUp defined and documented for TestCase is not a very nice interface. Better to put as much of the new logic as possible in the new class. (IMO) |
| In my mind all three Otherwise we have an overload for running test itself only but setup/teardown is rigidly pinned. See these lines from The PR customizes |
| @1st1, you requested changes. Is that what you had in mind? Personally, I am not sure that there is much left to do in TestCase at this point. |
| That's what I'm talking about: we need three hooks: set-up, run-test and tear-down. |
This allows a future subclass to customize how the test method is run. For
example, this is required in order to create an "AsyncTestCase" that runs
coroutines in an event loop.
This pull request only provides the neccessary change in unittest. Any future class like "AsyncTestCase" will probably live in asyncio.
https://bugs.python.org/issue32972