-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Drop unused unittest components from test helpers and replace tests with pytest-based ones #67
Conversation
4eba97d
to
5ff6a72
Compare
Codecov Report
@@ Coverage Diff @@
## master #67 +/- ##
=========================================
- Coverage 62.33% 18.34% -44%
=========================================
Files 15 15
Lines 2963 2748 -215
=========================================
- Hits 1847 504 -1343
- Misses 1116 2244 +1128 |
5ff6a72
to
5081f9c
Compare
Although it's found in the 'tests' package, the webtest module in particular is part of the public interface of cheroot and cherrypy. I did a quick search for ReloadingTestLoader, which turns up quite a few results. If there are users relying on this functionality, this change will need to describe what the recommendation is for those users. Maybe the recommendation is they adapt their tests to a new model--a fairly harsh ask. Or maybe we release this functionality in a separate package. I can't decide whether it's worth an intermediate release deprecating this functionality first. In any case, I'm largely in favor of this change as long as we can make it without causing undue disruption. |
cheroot/test/conftest.py
Outdated
|
||
|
||
config = { | ||
'bind_addr': ('127.0.0.1', 54583), |
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.
Here I'd like to see support for IPv6 and I'd like not to see hard-coded port numbers... which could conflict with other applications or other instances of the tests running. I suggest using portend.find_available_local_port
or binding to the ephemeral port 0 and then resolving the bind port for the client.
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.
Yeah, I was thinking about it and prefer ephemeral port 0 approach as it's safer to defer port allocation to the OS and portend
dependency is not even needed in this case.
I was trying to decouple existing unittest.TestCase
based class into pieces, thus I didn't really take any steps to optimize or add new behavior at this stage. I didn't even replace the test suite module, but added new one because of this experimenting process.
I followed the search and found out that all (or nearly all) of the results are just copies of cherrypy repo. |
Do you think anyone uses/needs If yes, do you have any ideas on how to reimplement this using pytest? |
I don't know about _handlewebError, but I would recommend that in a pytest scenario, one shouldn't use _handlewebError, and the tests should just make assertions and let the test runner handle interactivity (such as through --pdb). Given that it's got the underscore prefix, I'd say it's sane to deprecate/remove it. |
@jaraco well, it's kinda public, because depending on the environment variable (which I would consider to be a public interface) it intercepts assertion failures and provides an interactive interface for accessing/printing HTTP request/response values and suppressing/raising a real failures during test runs. On the other hand I don't really see any need for this interface. Also, I'd like to provide some new public pytest-oriented fixtures/helpers in |
It's not used in cheroot and is available in cherrypy copy of helper
cherrypy impl has it's own anyway
436a16a
to
c7825a2
Compare
Eliminated code duplication
While this workaround would work, I'd prefer keeping both requested and actual bind addrs within the server object, which might need bits of redesign.
@jaraco could you plz share your opinion regarding public helpers for end-users (aka |
I agree, creating an officially-supported |
Using ``--testmon`` breaks tests under Windows. Removing it temporarily. Ref: tarpas/pytest-testmon#81 Ref: https://ci.appveyor.com/project/CherryPy/cheroot/build/166/job/nlioynp1ls4xf3em#L215
This reverts commit 72ab1ea. Ref tarpas/pytest-testmon#84 Ref tarpas/pytest-testmon#14
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.
Overall, this is great. I see lots to love in this change. I could have added a few nitpicks, but I decided to refrain so we can get this out and iterate on it. I did add a couple of comments I think are worthy of addressing in this PR, but nothing glaring. And tests work for me.
I haven't tested it against CherryPy. If you can confirm CherryPy tests pass with these changes, I'm prepared to rubberstamp!
@@ -1600,6 +1603,7 @@ def bind(self, family, type, proto=0): | |||
pass | |||
|
|||
self.socket.bind(self.bind_addr) | |||
self.bind_addr = self.socket.getsockname()[:2] # TODO: keep separate |
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.
This change seems dangerous to me. You're overwriting the state on the object... so where one could previously access self.bind_addr
to determine what address was attempted to be bound, now one gets instead the addr than was bound. Plus, there's a TODO - not sure why not just do:
@property
def bound_addr(self):
return self.socket.getsockname()[:2]
or even better, just let the caller call server.socket.getsockname() directly.
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.
Yeah, it's just a dirty hack I did while refactoring tests. I wanted to postpone its resolution and to not dig into it while focusing on tests rewrite.
I don't want to mix this into the current PR, so I've logged this in #70
cheroot/server.py
Outdated
def _get_interrupt(self): | ||
@property | ||
def interrupt(self): | ||
"""Return interrupt Exception instance.""" |
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.
This docstring is the one that will be present on the property, whereas previously the docstring would have provided indication about setting the exception. The docstring should be copied from the setter and the setter should probably have no meaningful docstring, maybe something like "setter for interrupt".
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.
Fair enough
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.
But still the docstring should describe the property/getter
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.
I'll try to rephrase that
cheroot/test/webtest.py
Outdated
'We are moving to pytest-based testing and thus deprecating ' | ||
'WEBTEST_INTERACTIVE environment variable support. ' | ||
'Interactive test failure interceptor is going to be removed ' | ||
'in Cheroot v7.0.0', # TODO: decide whether it's v7 or v8 |
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.
I've learned that it's difficult to predict when a feature will be dropped unless you have a project with long iterations and scheduled releases, neither of which apply to cheroot. I would simply say "WEBTEST_INTERACTIVE is deprecated." ...and in a future, backward-incompatible release, which we will determine when we get to it, we drop support.
@jaraco thanks for the review! 💫 🚀 🤖 |
Confirmed that it's compatible with CherryPy |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Cleanup
What is the related issue number (starting with
#
)[TODO] Get rid of unittest.TestCase #42
What is the current behavior? (You can also link to an open issue here)
TerseTestResult, TerseTestRunner and ReloadingTestLoader exist.
What is the new behavior (if this is a feature change)?
Drop above.
Other information: