Skip to content

Commit

Permalink
Merge pull request #35097 from dimagi/dm/pytest-not-tests
Browse files Browse the repository at this point in the history
Tag test-looking things that are not tests
  • Loading branch information
millerdev authored Sep 5, 2024
2 parents ac14686 + 8c75186 commit 1e0ade6
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def diff_couch_and_sql(cls, couch, sql):


class TestDoc(SyncCouchToSQLMixin, Document):
__test__ = False

class Meta:
app_label = "couch"

Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/domain/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from corehq.apps.users.models import CommCareUser
from corehq.motech.utils import b64_aes_decrypt
from corehq.tests.tools import nottest
from corehq.util.test_utils import generate_cases, unit_testing_only


Expand Down Expand Up @@ -126,6 +127,7 @@ def test_return_value_is_json_serializable(self):
self.assertTrue(serialized_items)


@nottest
@contextmanager
def test_domain(name="domain", skip_full_delete=False):
"""Context manager for use in tests"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def rename(names, map={}, number=count()):
seen[sig] = test["name"]


class TestSequenceMeta(type):
class SequenceTestMeta(type):

def __new__(mcs, name, bases, dict):
tests_to_run = get_test_file_json('case_relationship_tests')
Expand All @@ -110,7 +110,7 @@ def __new__(mcs, name, bases, dict):


@sharded
class IndexTreeTest(BaseSyncTest, metaclass=TestSequenceMeta):
class IndexTreeTest(BaseSyncTest, metaclass=SequenceTestMeta):
"""Fetch all testcases from data/case_relationship_tests.json and run them
Each testcase is structured as follows:
Expand Down
2 changes: 1 addition & 1 deletion corehq/ex-submodules/dimagi/utils/tests/test_undo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class TestDocument(Document):
pass
__test__ = False


class TestSubDocument(TestDocument):
Expand Down
2 changes: 1 addition & 1 deletion corehq/ex-submodules/pillow_retry/tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


class TestException(Exception):
pass
__test__ = False


class TestMixin(object):
Expand Down
1 change: 1 addition & 0 deletions corehq/ex-submodules/pillowtop/processors/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TestProcessor(PillowProcessor):
"""
Processor that just keeps the change in an in-memory list for testing
"""
__test__ = False

def __init__(self):
self.changes_seen = []
Expand Down
5 changes: 5 additions & 0 deletions corehq/ex-submodules/pillowtop/tests/test_dao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from abc import abstractmethod
from django.test import SimpleTestCase
from django.utils.functional import classproperty
from fakecouch import FakeCouchDb
from pillowtop.dao.couch import CouchDocumentStore
from pillowtop.dao.exceptions import DocumentNotFoundError
Expand All @@ -8,6 +9,10 @@

class _AbstractDocumentStoreTestCase(SimpleTestCase):

@classproperty
def __test__(cls):
return not getattr(cls.dao.fget, "__isabstractmethod__", False)

@property
@abstractmethod
def dao(self):
Expand Down
1 change: 1 addition & 0 deletions corehq/form_processor/utils/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class TestFormMetadata(jsonobject.JsonObject):
time_start = jsonobject.DateTimeProperty(default=datetime(2013, 4, 19, 16, 53, 2))
# Set this property to fake the submission time
received_on = jsonobject.DateTimeProperty(default=datetime.utcnow)
__test__ = False


class FormSubmissionBuilder(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@
from corehq.sql_db.tests.utils import DefaultShardingTestConfigMixIn
from datetime import datetime, date
from django.test import TestCase
from django.utils.functional import classproperty


@only_run_with_partitioned_database
class BaseSchedulingPartitionedDBAccessorsTest(DefaultShardingTestConfigMixIn, TestCase):

@classproperty
def __test__(cls):
return cls is not BaseSchedulingPartitionedDBAccessorsTest

@classmethod
def setUpClass(cls):
super(BaseSchedulingPartitionedDBAccessorsTest, cls).setUpClass()
Expand Down
3 changes: 3 additions & 0 deletions corehq/tests/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import attr

from corehq.tests.tools import nottest

log = logging.getLogger(__name__)
_LOCK = Lock()

Expand Down Expand Up @@ -69,6 +71,7 @@ def real_redis_client():
_mock_redis_client = True


@nottest
@attr.s
class TestRedisClient:
lock = attr.ib()
Expand Down
3 changes: 3 additions & 0 deletions corehq/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def slow_function_view(request):
class TestReportDispatcher(ReportDispatcher):
map_name = "REPORTS"
prefix = "test"
__test__ = False

@classmethod
def get_reports(cls, domain):
Expand All @@ -50,6 +51,7 @@ def get_reports(cls, domain):
class TestNoDomainReportDispatcher(ReportDispatcher):
map_name = "REPORTS"
prefix = "test_no_domain"
__test__ = False

@classmethod
def get_reports(cls, domain):
Expand All @@ -61,6 +63,7 @@ def get_reports(cls, domain):
class TestCustomReportDispatcher(TestNoDomainReportDispatcher):
map_name = "REPORTS"
prefix = "test_custom"
__test__ = False

def dispatch(self, request, *args, **kwargs):
return CustomReport(request).view_response
Expand Down
4 changes: 4 additions & 0 deletions corehq/tests/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

def nottest(fn):
fn.__test__ = False
return fn
16 changes: 8 additions & 8 deletions corehq/tests/util/tests/test_warnings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
from difflib import unified_diff
from functools import wraps
from unittest import TestCase, TestResult, TestSuite
from unittest import TestCase, TestResult as Result, TestSuite as Suite
from unittest.mock import patch

from testil import Regex, assert_raises, eq
Expand Down Expand Up @@ -110,7 +110,7 @@ def runTest(self):
log.append("test")

log = []
TestSuite([Test()]).debug()
Suite([Test()]).debug()
eq(log, ["setup", "test", "teardown"])


Expand All @@ -133,8 +133,8 @@ def runTest(self):
log.append("test")

log = []
result = TestResult()
TestSuite([Test()]).run(result)
result = Result()
Suite([Test()]).run(result)
eq(str(result.errors), Regex(r" in setUpClass\\n .*Warning: fail"), result)
eq(log, ["setup"])

Expand All @@ -158,8 +158,8 @@ def runTest(self):
log.append("test") # should not get here

log = []
result = TestResult()
TestSuite([Test()]).run(result)
result = Result()
Suite([Test()]).run(result)
eq(str(result.errors), Regex(r" in runTest\\n .*Warning: fail"), result)
eq(log, ["setup", "teardown"])

Expand All @@ -182,7 +182,7 @@ def runTest(self):
log.append("test") # should not get here

log = []
result = TestResult()
TestSuite([Test()]).run(result)
result = Result()
Suite([Test()]).run(result)
eq(str(result.errors), Regex(r" in tearDownClass\\n .*Warning: fail"), result)
eq(log, ["setup", "test"])
5 changes: 5 additions & 0 deletions corehq/util/metrics/tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict, Tuple

from django.test import SimpleTestCase
from django.utils.functional import classproperty

from corehq.util.metrics.datadog import DatadogMetrics
from corehq.util.metrics.prometheus import PrometheusMetrics
Expand All @@ -12,6 +13,10 @@
class _TestMetrics(SimpleTestCase):
provider_class = None

@classproperty
def __test__(cls):
return cls.provider_class is not None

@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
1 change: 1 addition & 0 deletions corehq/util/tests/test_couch.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_get_document_or_404_success(self):


class TestLoggingDB(object):
__test__ = False

def __init__(self):
self.docs_saved = []
Expand Down

0 comments on commit 1e0ade6

Please sign in to comment.