Skip to content
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
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

EricGoulart
Copy link

Summary of Changes

Remove conditional dependency on testtools in TestCase to simplify maintenance and prepare for Falcon 5.0 where testtools will no longer be supported. Instead, unittest is now the default, and users are encouraged to use pytest for testing Falcon applications. This change emits a deprecation warning if testtools is still enabled via environment variables.

Related Issues

Closes #2156

Remove conditional dependency on testtools in TestCase to simplify maintenance and prepare for
Falcon 5.0 where testtools will no longer be supported. Instead, unittest is now the default,
and users are encouraged to use pytest for testing Falcon applications. This change emits a
deprecation warning if testtools is still enabled via environment variables.

Closes falconry#2156
Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.

Project coverage is 98.15%. Comparing base (cf51816) to head (358bcb2).

Files with missing lines Patch % Lines
falcon/testing/test_case.py 44.44% 8 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2405      +/-   ##
===========================================
- Coverage   100.00%   98.15%   -1.85%     
===========================================
  Files           64       64              
  Lines         7726     7742      +16     
  Branches      1071     1073       +2     
===========================================
- Hits          7726     7599     -127     
- Misses           0      123     +123     
- Partials         0       20      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks once again for this PR. 👍

It seems that it needs work before we can merge it, though:

  • A newsfragment is missing.
  • Test coverage for new code is missing.
  • The environment variable could be called FALCON_TEST_CASE, or FALCON_BASE_TEST_CASE. The value could be an import path with or without the .TestCase or ::TestCase suffix, e.g., FALCON_BASE_TEST_CASE=testtools.TestCase.
  • We shouldn't emit a deprecation warning just because testtools can be found in the current environment, but only when a TestCase is initialized with the base from testtools automagically. If provided via the envvar, testtools should continue to emit no warning.
  • I don't think we should write that we recommend pytest over unittest; although personally I could maybe sign under that recommendation, unittest continues to be very popular too. Moreover, you can use pytest to run unittest.TestCases, allowing even for a hybrid approach.

Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove important notes that were not added by you!

It seems that the updated changes are not really what was requested, could you take a look again? Thanks!

Moreover, code coverage does not reach 100%. You can run tox locally to check coverage before pushing changes for a public review; this might be more efficient in terms of the number of unnecessary iterations in the review process.


import falcon
import falcon.request

# TODO hoist for backwards compat. Remove in falcon 4.
Copy link
Member

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.

import testtools

warnings.warn(
'Support for testtools is deprecated and will be removed in Falcon 5.0.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested before, please do not warn just because the package is importable!
Only warn when a TestCase is actually initialized.

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

base_case = os.environ.get('FALCON_BASE_TEST_CASE')

if base_case and 'testtools.TestCase' in base_case:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to actually import the specified module, not just support testtools.TestCase.
It can be something.else.TestCase too.

@@ -0,0 +1,3 @@
- **Deprecation**: Support for `testtools` in `falcon.testing` is now deprecated and will be removed in Falcon 5.0.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't name the newsfragment .breakingchange., because we are not making any actual breaking changes until 5.0.

Since we are adding a new way to configure the base test case, I suggest marketing this as new feature.

"""

# NOTE(vytas): Here we have to restore __test__ to allow collecting tests!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you removed my note?

@vytas7 vytas7 marked this pull request as draft November 11, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate testtools support
2 participants