-
-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(testing): deprecate testtools support in TestCase #2405
Draft
EricGoulart
wants to merge
4
commits into
falconry:master
Choose a base branch
from
EricGoulart:issue_2156
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c6e6559
refactor(testing): deprecate testtools support in TestCase
EricGoulart 59ed398
implementing requested improvements
EricGoulart 358bcb2
Merge branch 'master' into issue_2156
vytas7 8952f71
updating changes, still missing test covarage
EricGoulart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,15 +18,25 @@ | |
utilities for simulating and validating HTTP requests. | ||
""" | ||
|
||
try: | ||
import testtools as unittest | ||
except ImportError: # pragma: nocover | ||
import unittest | ||
import os | ||
import unittest | ||
import warnings | ||
|
||
if 'DISABLE_TESTTOOLS' not in os.environ: | ||
try: | ||
import testtools | ||
|
||
warnings.warn( | ||
'Support for testtools is deprecated and will be removed in Falcon 5.0. ' | ||
'Please migrate to unittest or pytest.', | ||
DeprecationWarning, | ||
) | ||
BaseTestCase = testtools.TestCase | ||
except ImportError: # pragma: nocover | ||
BaseTestCase = unittest.TestCase | ||
|
||
import falcon | ||
import falcon.request | ||
|
||
# TODO hoist for backwards compat. Remove in falcon 4. | ||
from falcon.testing.client import Result # NOQA | ||
from falcon.testing.client import TestClient | ||
|
||
|
@@ -35,16 +45,45 @@ | |
"""Extends :mod:`unittest` to support WSGI/ASGI functional testing. | ||
|
||
Note: | ||
If available, uses :mod:`testtools` in lieu of | ||
:mod:`unittest`. | ||
This class uses :mod:`unittest` by default. If :mod:`testtools` | ||
is available and the environment variable | ||
``DISABLE_TESTTOOLS`` is **not** set, it will use :mod:`testtools` instead. | ||
**Support for testtools is deprecated and will be removed in Falcon 5.0.** | ||
|
||
Recommended: | ||
We recommend using **pytest** for testing Falcon applications. | ||
See our tutorial on using pytest. | ||
|
||
This base class provides some extra plumbing for unittest-style | ||
test cases, to help simulate WSGI or ASGI requests without having | ||
to spin up an actual web server. Various simulation methods are | ||
derived from :class:`falcon.testing.TestClient`. | ||
|
||
Simply inherit from this class in your test case classes instead of | ||
:class:`unittest.TestCase` or :class:`testtools.TestCase`. | ||
:class:`unittest.TestCase`. | ||
|
||
For example:: | ||
|
||
from falcon import testing | ||
import myapp | ||
|
||
|
||
class MyTestCase(testing.TestCase): | ||
def setUp(self): | ||
super(MyTestCase, self).setUp() | ||
|
||
# Assume the hypothetical `myapp` package has a | ||
# function called `create()` to initialize and | ||
# return a `falcon.App` instance. | ||
self.app = myapp.create() | ||
|
||
|
||
class TestMyApp(MyTestCase): | ||
def test_get_message(self): | ||
doc = {'message': 'Hello world!'} | ||
|
||
result = self.simulate_get('/messages/42') | ||
self.assertEqual(result.json, doc) | ||
""" | ||
|
||
# NOTE(vytas): Here we have to restore __test__ to allow collecting tests! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you removed my note? |
||
|
@@ -69,14 +108,6 @@ | |
# function called `create()` to initialize and | ||
# return a `falcon.App` instance. | ||
self.app = myapp.create() | ||
|
||
|
||
class TestMyApp(MyTestCase): | ||
def test_get_message(self): | ||
doc = {'message': 'Hello world!'} | ||
|
||
result = self.simulate_get('/messages/42') | ||
self.assertEqual(result.json, doc) | ||
""" | ||
|
||
def setUp(self) -> None: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove this note!
We missed it in Falcon 4.0 it seems, so it needs to be updated to say Falcon 5.0, if you want to touch it.