def filthiness(test): """Return a score of how messy a test leaves the environment. Django's TransactionTestCase doesn't clean up the DB on teardown, but it's hard to guess whether subclasses (other than TestCase) do. We will assume they don't, unless they have a ``cleans_up_after_itself`` attr set to True. This is reasonable because the odd behavior of TransactionTestCase is documented, so subclasses should by default be assumed to preserve it. Thus, things will get these comparands (and run in this order): * 1: TestCase subclasses. These clean up after themselves. * 1: TransactionTestCase subclasses with cleans_up_after_itself=True. These include FastFixtureTestCases. If you're using the FixtureBundlingPlugin, it will pull the FFTCs out, reorder them, and run them first of all. * 2: TransactionTestCase subclasses. These leave a mess. * 2: Anything else (including doctests, I hope). These don't care about the mess you left, because they don't hit the DB or, if they do, are responsible for ensuring that it's clean (as per https://docs.djangoproject.com/en/dev/topics/testing/?from= olddocs#writing-doctests) """ test_class = test.context if (is_subclass_at_all(test_class, TestCase) or (is_subclass_at_all(test_class, TransactionTestCase) and getattr(test_class, 'cleans_up_after_itself', False))): return 1 return 2
def filthiness(test): """Return a comparand based on whether a test is guessed to clean up after itself. Django's TransactionTestCase doesn't clean up the DB on teardown, but it's hard to guess whether subclasses (other than TestCase) do. We will assume they don't, unless they have a ``cleans_up_after_itself`` attr set to True. This is reasonable because the odd behavior of TransactionTestCase is documented, so subclasses should by default be assumed to preserve it. Thus, things will get these comparands (and run in this order): * 1: TestCase subclasses. These clean up after themselves. * 1: TransactionTestCase subclasses with cleans_up_after_itself=True. These include FastFixtureTestCases. If you're using the FixtureBundlingPlugin, it will pull the FFTCs out, reorder them, and run them first of all. * 2: TransactionTestCase subclasses. These leave a mess. * 2: Anything else (including doctests, I hope). These don't care about the mess you left, because they don't hit the DB or, if they do, are responsible for ensuring that it's clean (as per https://docs.djangoproject.com/en/dev/topics/testing/?from= olddocs#writing-doctests) """ test_class = test.context if (is_subclass_at_all(test_class, TestCase) or (is_subclass_at_all(test_class, TransactionTestCase) and getattr(test_class, 'cleans_up_after_itself', False))): return 1 return 2
def _get_test_cases(self, suite): if is_subclass_at_all(suite.context, unittest.TestCase): return [suite.context] test_clases = [] if hasattr(suite, '_get_tests'): for test in suite._get_tests(): test_clases += self._get_test_cases(test) return test_clases
def add(self, test): """Put a test into a bucket according to its set of fixtures and the value of its exempt_from_fixture_bundling attr.""" if is_subclass_at_all(test.context, FastFixtureTestCase): # We bucket even FFTCs that don't have any fixtures, but it # shouldn't matter. key = (frozenset(getattr(test.context, 'fixtures', [])), getattr(test.context, 'exempt_from_fixture_bundling', False)) self.buckets.setdefault(key, []).append(test) else: self.remainder.append(test)
def add(self, test): """Add test into an initialization bucket. Tests are bucketed according to its set of fixtures and the value of its exempt_from_fixture_bundling attr. """ if is_subclass_at_all(test.context, FastFixtureTestCase): # We bucket even FFTCs that don't have any fixtures, but it # shouldn't matter. key = ( frozenset(getattr(test.context, "fixtures", [])), getattr(test.context, "exempt_from_fixture_bundling", False), ) self.buckets.setdefault(key, []).append(test) else: self.remainder.append(test)