Skip to content

Commit

Permalink
Prevent PytestCollectionWarning for TestApp
Browse files Browse the repository at this point in the history
As per my blog post: https://adamj.eu/tech/2020/07/28/how-to-fix-a-pytest-collection-warning-about-web-tests-test-app-class/

pytest tries to collect `TestApp` where it's imported and raises a warning when it finds it's not a test class. Users currently have to work around this, but it can be solved here by addition of this attribute.
  • Loading branch information
adamchainz committed Jul 28, 2020
1 parent 4c27a07 commit 0339515
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class TestApp(unittest.TestCase):
def setUp(self):
self.app = webtest.TestApp(debug_app)

def test_pytest_collection_disabled(self):
self.assertFalse(webtest.TestApp.__test__)

def test_encode_multipart_relative_to(self):
app = webtest.TestApp(debug_app,
relative_to=os.path.dirname(__file__))
Expand Down
3 changes: 3 additions & 0 deletions webtest/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class TestApp(object):

RequestClass = TestRequest

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

def __init__(self, app, extra_environ=None, relative_to=None,
use_unicode=True, cookiejar=None, parser_features=None,
json_encoder=None, lint=True):
Expand Down

0 comments on commit 0339515

Please sign in to comment.