Skip to content

Commit

Permalink
updating changes, still missing test covarage
Browse files Browse the repository at this point in the history
  • Loading branch information
EricGoulart committed Nov 11, 2024
1 parent 358bcb2 commit 8952f71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
File renamed without changes.
42 changes: 27 additions & 15 deletions falcon/testing/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@
utilities for simulating and validating HTTP requests.
"""

from importlib import import_module
import os
import unittest
import warnings

try:
import testtools as unittest
except ImportError: # pragma: nocover
import unittest

import falcon
import falcon.request
from falcon.testing.client import Result # NOQA
from falcon.testing.client import TestClient

base_case = os.environ.get('FALCON_BASE_TEST_CASE')
# TODO hoist for backwards compat. Remove in falcon 5.

if base_case and 'testtools.TestCase' in base_case:
try:
import testtools
base_case_path = os.environ.get('FALCON_BASE_TEST_CASE')

BaseTestCase = testtools.TestCase
except ImportError:
BaseTestCase = unittest.TestCase
elif base_case is None:
if base_case_path:
try:
import testtools

module_path, class_name = base_case_path.rsplit('.', 1)
module = import_module(module_path)
BaseTestCase = getattr(module, class_name)
except (ImportError, AttributeError):
warnings.warn(
'Support for testtools is deprecated and will be removed in Falcon 5.0.',
DeprecationWarning,
f"Could not import '{base_case_path}', defaulting to testtools.TestCase.",
ImportWarning,
)
BaseTestCase = testtools.TestCase
except ImportError:
BaseTestCase = unittest.TestCase
else:
BaseTestCase = unittest.TestCase
Expand Down Expand Up @@ -91,6 +91,7 @@ def test_get_message(self):
self.assertEqual(result.json, doc)
"""

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

app: falcon.App
Expand All @@ -116,6 +117,17 @@ def setUp(self):
def setUp(self) -> None:
super(TestCase, self).setUp()

if (
BaseTestCase == unittest.TestCase
and os.environ.get('FALCON_BASE_TEST_CASE') is None
and 'testtools' in str(unittest)
):
warnings.warn(
'Support for testtools is deprecated'
'and will be removed in Falcon 5.0.',
DeprecationWarning,
)

app = falcon.App()

# NOTE(kgriffs): Don't use super() to avoid triggering
Expand Down

0 comments on commit 8952f71

Please sign in to comment.