Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Avoid use of Python internal __unittest_skip__ flag.

Anders Kaseorg43ee1f7b936d
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 8e3772fe2b2..5e64ace1f60 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -7,6 +7,7 @@ import re
import secrets
import time
import urllib
+from abc import ABC, abstractmethod
from contextlib import contextmanager
from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Type
from unittest import mock
@@ -825,7 +826,7 @@ class DesktopFlowTestingLib(ZulipTestCase):
return AESGCM(key).decrypt(iv, ciphertext, b"").decode()
-class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
+class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase, ABC):
"""This is a base class for testing social-auth backends. These
methods are often overridden by subclasses:
@@ -836,10 +837,6 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
according to the respective backend.
"""
- # Don't run base class tests, make sure to set it to False
- # in subclass otherwise its tests will not run.
- __unittest_skip__ = True
-
BACKEND_CLASS: "Type[SocialAuthMixin]"
LOGIN_URL: str
SIGNUP_URL: str
@@ -850,9 +847,9 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
CLIENT_KEY_SETTING: str
CLIENT_SECRET_SETTING: str
- # Functions that subclasses must implement.
+ @abstractmethod
def get_account_data_dict(self, email: str, name: str) -> Dict[str, Any]:
- ...
+ raise NotImplementedError
def setUp(self) -> None:
super().setUp()
@@ -1866,8 +1863,6 @@ class SocialAuthBase(DesktopFlowTestingLib, ZulipTestCase):
class SAMLAuthBackendTest(SocialAuthBase):
- __unittest_skip__ = False
-
BACKEND_CLASS = SAMLAuthBackend
LOGIN_URL = "/accounts/login/social/saml/test_idp"
SIGNUP_URL = "/accounts/register/social/saml/test_idp"
@@ -2945,8 +2940,6 @@ class AppleAuthMixin:
class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase):
- __unittest_skip__ = False
-
LOGIN_URL = "/accounts/login/social/apple"
SIGNUP_URL = "/accounts/register/social/apple"
@@ -3076,8 +3069,6 @@ class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase):
class AppleAuthBackendNativeFlowTest(AppleAuthMixin, SocialAuthBase):
- __unittest_skip__ = False
-
SIGNUP_URL = "/complete/apple/"
LOGIN_URL = "/complete/apple/"
@@ -3284,8 +3275,6 @@ class AppleAuthBackendNativeFlowTest(AppleAuthMixin, SocialAuthBase):
class GenericOpenIdConnectTest(SocialAuthBase):
- __unittest_skip__ = False
-
BACKEND_CLASS = GenericOpenIdConnectBackend
CLIENT_KEY_SETTING = "SOCIAL_AUTH_TESTOIDC_KEY"
CLIENT_SECRET_SETTING = "SOCIAL_AUTH_TESTOIDC_SECRET"
@@ -3497,8 +3486,6 @@ class GenericOpenIdConnectTest(SocialAuthBase):
class GitHubAuthBackendTest(SocialAuthBase):
- __unittest_skip__ = False
-
BACKEND_CLASS = GitHubAuthBackend
CLIENT_KEY_SETTING = "SOCIAL_AUTH_GITHUB_KEY"
CLIENT_SECRET_SETTING = "SOCIAL_AUTH_GITHUB_SECRET"
@@ -4018,8 +4005,6 @@ class GitHubAuthBackendTest(SocialAuthBase):
class GitLabAuthBackendTest(SocialAuthBase):
- __unittest_skip__ = False
-
BACKEND_CLASS = GitLabAuthBackend
CLIENT_KEY_SETTING = "SOCIAL_AUTH_GITLAB_KEY"
CLIENT_SECRET_SETTING = "SOCIAL_AUTH_GITLAB_SECRET"
@@ -4039,8 +4024,6 @@ class GitLabAuthBackendTest(SocialAuthBase):
class GoogleAuthBackendTest(SocialAuthBase):
- __unittest_skip__ = False
-
BACKEND_CLASS = GoogleAuthBackend
CLIENT_KEY_SETTING = "SOCIAL_AUTH_GOOGLE_KEY"
CLIENT_SECRET_SETTING = "SOCIAL_AUTH_GOOGLE_SECRET"
@@ -6776,3 +6759,7 @@ class LDAPBackendTest(ZulipTestCase):
warn_log.output,
["WARNING:django_auth_ldap:('Realm is None', 1) while authenticating hamlet"],
)
+
+
+# Don't load the base class as a test: https://bugs.python.org/issue17519.
+del SocialAuthBase
diff --git a/zerver/tests/test_rate_limiter.py b/zerver/tests/test_rate_limiter.py
index 61d6051e570..57c83b95f3d 100644
--- a/zerver/tests/test_rate_limiter.py
+++ b/zerver/tests/test_rate_limiter.py
@@ -1,5 +1,6 @@
import secrets
import time
+from abc import ABC, abstractmethod
from typing import Dict, List, Tuple, Type
from unittest import mock
@@ -34,9 +35,7 @@ class RateLimitedTestObject(RateLimitedObject):
return self._rules
-class RateLimiterBackendBase(ZulipTestCase):
- __unittest_skip__ = True
-
+class RateLimiterBackendBase(ZulipTestCase, ABC):
def setUp(self) -> None:
self.requests_record: Dict[str, List[float]] = {}
@@ -84,6 +83,7 @@ class RateLimiterBackendBase(ZulipTestCase):
return self.api_calls_left_from_history(history, max_window, max_calls, now)
+ @abstractmethod
def api_calls_left_from_history(
self, history: List[float], max_window: int, max_calls: int, now: float
) -> Tuple[int, float]:
@@ -151,7 +151,6 @@ class RateLimiterBackendBase(ZulipTestCase):
class RedisRateLimiterBackendTest(RateLimiterBackendBase):
- __unittest_skip__ = False
backend = RedisRateLimiterBackend
def api_calls_left_from_history(
@@ -177,7 +176,6 @@ class RedisRateLimiterBackendTest(RateLimiterBackendBase):
class TornadoInMemoryRateLimiterBackendTest(RateLimiterBackendBase):
- __unittest_skip__ = False
backend = TornadoInMemoryRateLimiterBackend
def api_calls_left_from_history(
@@ -244,3 +242,7 @@ class RateLimitedObjectsTest(ZulipTestCase):
def test_empty_rules_edge_case(self) -> None:
obj = RateLimitedTestObject("test", rules=[], backend=RedisRateLimiterBackend)
self.assertEqual(obj.get_rules(), [(1, 9999)])
+
+
+# Don't load the base class as a test: https://bugs.python.org/issue17519.
+del RateLimiterBackendBase