Skip to content

Commit

Permalink
Prevent PytestCollectionWarning for TestRequest, TestResponse
Browse files Browse the repository at this point in the history
Prevents mildly annoying warnings in pytest of the form:

PytestCollectionWarning: cannot collect test class 'TestResponse' because it has a __init__ constructor (from: test/test_foo.py)
    class TestResponse(webob.Response):

This has already been fixed for TestApp in
0339515, but TestRequest and
TestResponse were missed. But pytest will try to collect all classes
whose name starts with "Test". A quick grep confirms that these three
are the only webtest classes starting with "Test".
  • Loading branch information
vbraun committed Mar 4, 2024
1 parent 5bc6841 commit c8ec3b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,9 @@ def test_xhr_param_change_headers(self):
resp.charset = 'ascii'
self.assertIn('HTTP_X_REQUESTED_WITH: XMLHttpRequest',
resp.text)


class TestRequest(unittest.TestCase):

def test_pytest_collection_disabled(self):
self.assertFalse(webtest.TestRequest.__test__)
3 changes: 3 additions & 0 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,6 @@ def test_maybe_follow_twice(self):
def test_maybe_follow_infinite(self):
app = self.get_redirects_app(100000)
self.assertRaises(AssertionError, app.get('/').maybe_follow)

def test_pytest_collection_disabled(self):
self.assertFalse(webtest.TestResponse.__test__)
4 changes: 4 additions & 0 deletions webtest/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def set_ok_domain(self, cookie, request):

class TestRequest(webob.BaseRequest):
"""A subclass of webob.Request"""

# Tell pytest not to collect this class as tests
__test__ = False

ResponseClass = TestResponse


Expand Down
3 changes: 3 additions & 0 deletions webtest/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class TestResponse(webob.Response):
_forms_indexed = None
parser_features = 'html.parser'

# Tell pytest not to collect this class as tests
__test__ = False

@property
def forms(self):
"""
Expand Down

0 comments on commit c8ec3b7

Please sign in to comment.