Skip to content

Commit

Permalink
Merge pull request #257 from vbraun/pytest_testresponse_warning
Browse files Browse the repository at this point in the history
Prevent PytestCollectionWarning for TestRequest, TestResponse
  • Loading branch information
gawel authored Mar 4, 2024
2 parents 5bc6841 + c8ec3b7 commit 5495860
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 5495860

Please sign in to comment.