summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2020-07-28 08:45:57 +0100
committerAdam Johnson <me@adamj.eu>2020-07-28 08:51:40 +0100
commit03395151089dd58170f9542c99dbee6f20eeb090 (patch)
treea1f1f644bf365d3e840263c49cd2ca31cf158a63
parent4c27a07730763d3d63d132a75d822a4f29179adc (diff)
downloadwebtest-03395151089dd58170f9542c99dbee6f20eeb090.tar.gz
Prevent PytestCollectionWarning for TestApp
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.
-rw-r--r--tests/test_app.py3
-rw-r--r--webtest/app.py3
2 files changed, 6 insertions, 0 deletions
diff --git a/tests/test_app.py b/tests/test_app.py
index 0c611fb..c823baa 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -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__))
diff --git a/webtest/app.py b/webtest/app.py
index fe7011f..ccf5c5c 100644
--- a/webtest/app.py
+++ b/webtest/app.py
@@ -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):