Skip to content

Commit

Permalink
fix: prevent pytest from collecting tests on testing.TestClient (#2148)
Browse files Browse the repository at this point in the history
* fix: prevent pytest from collecting tests on testing.TestClient

* chore: remove extraneous whitespace

* docs(towncrier): add a newsfragment

* fix(testing): allow collecting tests from TestCases (duh!)

* chore: prefix comments

---------

Co-authored-by: Aryan Iyappan <69184573+aryan340@users.noreply.github.com>
Co-authored-by: Vytautas Liuolia <vytautas.liuolia@gmail.com>
  • Loading branch information
3 people committed Jun 3, 2023
1 parent 200a853 commit b16b6c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/_newsfragments/2147.bugfix.rst
@@ -0,0 +1,4 @@
Previously, importing :class:`~falcon.testing.TestCase` as a top-level
attribute in a test module could make ``pytest`` erroneously attempt to collect
its methods as test cases. This has now been prevented by adding a ``__test__``
attribute (set to ``False``) to the :class:`~falcon.testing.TestCase` class.
3 changes: 3 additions & 0 deletions falcon/testing/client.py
Expand Up @@ -1970,6 +1970,9 @@ class TestClient:
"""

# NOTE(aryaniyaps): Prevent pytest from collecting tests on the class.
__test__ = False

def __init__(self, app, headers=None):
self.app = app
self._default_headers = headers
Expand Down
3 changes: 3 additions & 0 deletions falcon/testing/test_case.py
Expand Up @@ -75,6 +75,9 @@ def test_get_message(self):
self.assertEqual(result.json, doc)
"""

# NOTE(vytas): Here we have to restore __test__ to allow collecting tests!
__test__ = True

def setUp(self):
super(TestCase, self).setUp()

Expand Down

0 comments on commit b16b6c3

Please sign in to comment.