# HG changeset patch # User Marc Abramowitz # Date 2015-04-21 15:35:36 # Node ID 12ae08b2fe3f168ac42c2f009eadee2f4c000c0f # Parent 5c8c77b7ca565ffa193868f3469c26e39630cfb4 tests: avoid executing tests in base classes Fixes lots of failures with pytest by making sure base test classes don't inherit from unittest.TestCase or by prefacing name with an underscore so tests don't get executed by pytest. diff --git a/kallithea/tests/api/api_base.py b/kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py +++ b/kallithea/tests/api/api_base.py @@ -88,7 +88,7 @@ def make_repo_group(name=TEST_REPO_GROUP return gr -class BaseTestApi(object): +class _BaseTestApi(object): REPO = None REPO_TYPE = None diff --git a/kallithea/tests/api/test_api_git.py b/kallithea/tests/api/test_api_git.py --- a/kallithea/tests/api/test_api_git.py +++ b/kallithea/tests/api/test_api_git.py @@ -13,9 +13,9 @@ # along with this program. If not, see . from kallithea.tests import * -from kallithea.tests.api.api_base import BaseTestApi +from kallithea.tests.api.api_base import _BaseTestApi -class TestGitApi(BaseTestApi, TestController): +class TestGitApi(_BaseTestApi, TestController): REPO = GIT_REPO REPO_TYPE = 'git' diff --git a/kallithea/tests/api/test_api_hg.py b/kallithea/tests/api/test_api_hg.py --- a/kallithea/tests/api/test_api_hg.py +++ b/kallithea/tests/api/test_api_hg.py @@ -13,9 +13,9 @@ # along with this program. If not, see . from kallithea.tests import * -from kallithea.tests.api.api_base import BaseTestApi +from kallithea.tests.api.api_base import _BaseTestApi -class TestHgApi(BaseTestApi, TestController): +class TestHgApi(_BaseTestApi, TestController): REPO = HG_REPO REPO_TYPE = 'hg' diff --git a/kallithea/tests/functional/test_admin_repos.py b/kallithea/tests/functional/test_admin_repos.py --- a/kallithea/tests/functional/test_admin_repos.py +++ b/kallithea/tests/functional/test_admin_repos.py @@ -26,7 +26,7 @@ def _get_permission_for_user(user, repo) return perm -class _BaseTest(TestController): +class _BaseTest(object): """ Write all tests here """ @@ -638,7 +638,7 @@ class _BaseTest(TestController): # repo must not be in filesystem ! self.assertFalse(os.path.isdir(os.path.join(TESTS_TMP_PATH, repo_name))) -class TestAdminReposControllerGIT(_BaseTest): +class TestAdminReposControllerGIT(TestController, _BaseTest): REPO = GIT_REPO REPO_TYPE = 'git' NEW_REPO = NEW_GIT_REPO @@ -646,7 +646,7 @@ class TestAdminReposControllerGIT(_BaseT OTHER_TYPE = 'hg' -class TestAdminReposControllerHG(_BaseTest): +class TestAdminReposControllerHG(TestController, _BaseTest): REPO = HG_REPO REPO_TYPE = 'hg' NEW_REPO = NEW_HG_REPO diff --git a/kallithea/tests/functional/test_forks.py b/kallithea/tests/functional/test_forks.py --- a/kallithea/tests/functional/test_forks.py +++ b/kallithea/tests/functional/test_forks.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- + +import unittest + from kallithea.tests import * from kallithea.tests.fixture import Fixture @@ -12,15 +15,7 @@ fixture = Fixture() from kallithea.tests import * -class _BaseTest(TestController): - """ - Write all tests here - """ - REPO = None - REPO_TYPE = None - NEW_REPO = None - REPO_FORK = None - +class _BaseFixture(unittest.TestCase): @classmethod def setup_class(cls): pass @@ -40,6 +35,16 @@ class _BaseTest(TestController): Session().delete(self.u1) Session().commit() + +class _BaseTestCase(object): + """ + Write all tests here + """ + REPO = None + REPO_TYPE = None + NEW_REPO = None + REPO_FORK = None + def test_index(self): self.log_user() repo_name = self.REPO @@ -218,14 +223,14 @@ class _BaseTest(TestController): response.mustcontain('There are no forks yet') -class TestGIT(_BaseTest): +class TestGIT(TestController, _BaseTestCase, _BaseFixture): REPO = GIT_REPO NEW_REPO = NEW_GIT_REPO REPO_TYPE = 'git' REPO_FORK = GIT_FORK -class TestHG(_BaseTest): +class TestHG(TestController, _BaseTestCase, _BaseFixture): REPO = HG_REPO NEW_REPO = NEW_HG_REPO REPO_TYPE = 'hg' diff --git a/kallithea/tests/vcs/base.py b/kallithea/tests/vcs/base.py --- a/kallithea/tests/vcs/base.py +++ b/kallithea/tests/vcs/base.py @@ -13,7 +13,7 @@ from kallithea.lib.vcs.utils.compat impo from kallithea.lib.vcs.nodes import FileNode -class BackendTestMixin(object): +class _BackendTestMixin(object): """ This is a backend independent test case class which should be created with ``type`` method. @@ -103,7 +103,7 @@ for alias in SCM_TESTS: 'backend_alias': alias, } cls_name = ''.join(('%s base backend test' % alias).title().split()) - bases = (BackendTestMixin, unittest.TestCase) + bases = (_BackendTestMixin, unittest.TestCase) globals()[cls_name] = type(cls_name, bases, attrs) diff --git a/kallithea/tests/vcs/test_archives.py b/kallithea/tests/vcs/test_archives.py --- a/kallithea/tests/vcs/test_archives.py +++ b/kallithea/tests/vcs/test_archives.py @@ -6,14 +6,14 @@ import zipfile import datetime import tempfile import StringIO -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.exceptions import VCSError from kallithea.lib.vcs.nodes import FileNode from kallithea.lib.vcs.utils.compat import unittest -class ArchivesTestCaseMixin(BackendTestMixin): +class ArchivesTestCaseMixin(_BackendTestMixin): @classmethod def _get_commits(cls): diff --git a/kallithea/tests/vcs/test_branches.py b/kallithea/tests/vcs/test_branches.py --- a/kallithea/tests/vcs/test_branches.py +++ b/kallithea/tests/vcs/test_branches.py @@ -5,11 +5,11 @@ from kallithea.lib import vcs from kallithea.lib.vcs.utils.compat import unittest from kallithea.lib.vcs.nodes import FileNode -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS -class BranchesTestCaseMixin(BackendTestMixin): +class BranchesTestCaseMixin(_BackendTestMixin): @classmethod def _get_commits(cls): diff --git a/kallithea/tests/vcs/test_changesets.py b/kallithea/tests/vcs/test_changesets.py --- a/kallithea/tests/vcs/test_changesets.py +++ b/kallithea/tests/vcs/test_changesets.py @@ -4,7 +4,7 @@ from __future__ import with_statement import time import datetime from kallithea.lib import vcs -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.backends.base import BaseChangeset @@ -50,7 +50,7 @@ class TestBaseChangeset(unittest.TestCas 'removed': [], }) -class ChangesetsWithCommitsTestCaseixin(BackendTestMixin): +class _ChangesetsWithCommitsTestCaseixin(_BackendTestMixin): recreate_repo_per_test = True @classmethod @@ -146,7 +146,7 @@ class ChangesetsWithCommitsTestCaseixin( self.assertEqual([sha], self.repo.get_changeset(test_rev).children) -class ChangesetsTestCaseMixin(BackendTestMixin): +class _ChangesetsTestCaseMixin(_BackendTestMixin): recreate_repo_per_test = False @classmethod @@ -301,7 +301,7 @@ class ChangesetsTestCaseMixin(BackendTes list(self.repo.get_changesets(start=last-1, end=0)) -class ChangesetsChangesTestCaseMixin(BackendTestMixin): +class _ChangesetsChangesTestCaseMixin(_BackendTestMixin): recreate_repo_per_test = False @classmethod @@ -373,17 +373,17 @@ for alias in SCM_TESTS: } # tests with additional commits cls_name = ''.join(('%s changesets with commits test' % alias).title().split()) - bases = (ChangesetsWithCommitsTestCaseixin, unittest.TestCase) + bases = (_ChangesetsWithCommitsTestCaseixin, unittest.TestCase) globals()[cls_name] = type(cls_name, bases, attrs) # tests without additional commits cls_name = ''.join(('%s changesets test' % alias).title().split()) - bases = (ChangesetsTestCaseMixin, unittest.TestCase) + bases = (_ChangesetsTestCaseMixin, unittest.TestCase) globals()[cls_name] = type(cls_name, bases, attrs) # tests changes cls_name = ''.join(('%s changesets changes test' % alias).title().split()) - bases = (ChangesetsChangesTestCaseMixin, unittest.TestCase) + bases = (_ChangesetsChangesTestCaseMixin, unittest.TestCase) globals()[cls_name] = type(cls_name, bases, attrs) diff --git a/kallithea/tests/vcs/test_getitem.py b/kallithea/tests/vcs/test_getitem.py --- a/kallithea/tests/vcs/test_getitem.py +++ b/kallithea/tests/vcs/test_getitem.py @@ -1,13 +1,13 @@ from __future__ import with_statement import datetime -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.nodes import FileNode from kallithea.lib.vcs.utils.compat import unittest -class GetitemTestCaseMixin(BackendTestMixin): +class GetitemTestCaseMixin(_BackendTestMixin): @classmethod def _get_commits(cls): diff --git a/kallithea/tests/vcs/test_getslice.py b/kallithea/tests/vcs/test_getslice.py --- a/kallithea/tests/vcs/test_getslice.py +++ b/kallithea/tests/vcs/test_getslice.py @@ -1,13 +1,13 @@ from __future__ import with_statement import datetime -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.nodes import FileNode from kallithea.lib.vcs.utils.compat import unittest -class GetsliceTestCaseMixin(BackendTestMixin): +class GetsliceTestCaseMixin(_BackendTestMixin): @classmethod def _get_commits(cls): diff --git a/kallithea/tests/vcs/test_git.py b/kallithea/tests/vcs/test_git.py --- a/kallithea/tests/vcs/test_git.py +++ b/kallithea/tests/vcs/test_git.py @@ -8,7 +8,7 @@ from kallithea.lib.vcs.backends.git impo from kallithea.lib.vcs.exceptions import RepositoryError, VCSError, NodeDoesNotExistError from kallithea.lib.vcs.nodes import NodeKind, FileNode, DirNode, NodeState from kallithea.lib.vcs.utils.compat import unittest -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import TEST_GIT_REPO, TEST_GIT_REPO_CLONE, get_new_dir @@ -620,7 +620,7 @@ class GitSpecificTest(unittest.TestCase) changeset.added -class GitSpecificWithRepoTest(BackendTestMixin, unittest.TestCase): +class GitSpecificWithRepoTest(_BackendTestMixin, unittest.TestCase): backend_alias = 'git' @classmethod @@ -688,7 +688,7 @@ class GitSpecificWithRepoTest(BackendTes % (3, self.repo._get_revision(0), self.repo._get_revision(1))) -class GitRegressionTest(BackendTestMixin, unittest.TestCase): +class GitRegressionTest(_BackendTestMixin, unittest.TestCase): backend_alias = 'git' @classmethod diff --git a/kallithea/tests/vcs/test_repository.py b/kallithea/tests/vcs/test_repository.py --- a/kallithea/tests/vcs/test_repository.py +++ b/kallithea/tests/vcs/test_repository.py @@ -1,6 +1,6 @@ from __future__ import with_statement import datetime -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.tests.vcs.conf import TEST_USER_CONFIG_FILE from kallithea.lib.vcs.nodes import FileNode @@ -8,7 +8,7 @@ from kallithea.lib.vcs.utils.compat impo from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError -class RepositoryBaseTest(BackendTestMixin): +class RepositoryBaseTest(_BackendTestMixin): recreate_repo_per_test = False @classmethod @@ -46,7 +46,7 @@ class RepositoryBaseTest(BackendTestMixi self.assertTrue(self.repo != dummy()) -class RepositoryGetDiffTest(BackendTestMixin): +class RepositoryGetDiffTest(_BackendTestMixin): @classmethod def _get_commits(cls): diff --git a/kallithea/tests/vcs/test_tags.py b/kallithea/tests/vcs/test_tags.py --- a/kallithea/tests/vcs/test_tags.py +++ b/kallithea/tests/vcs/test_tags.py @@ -1,13 +1,13 @@ from __future__ import with_statement -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS from kallithea.lib.vcs.exceptions import TagAlreadyExistError from kallithea.lib.vcs.exceptions import TagDoesNotExistError from kallithea.lib.vcs.utils.compat import unittest -class TagsTestCaseMixin(BackendTestMixin): +class TagsTestCaseMixin(_BackendTestMixin): def test_new_tag(self): tip = self.repo.get_changeset() diff --git a/kallithea/tests/vcs/test_workdirs.py b/kallithea/tests/vcs/test_workdirs.py --- a/kallithea/tests/vcs/test_workdirs.py +++ b/kallithea/tests/vcs/test_workdirs.py @@ -3,11 +3,11 @@ from __future__ import with_statement import datetime from kallithea.lib.vcs.nodes import FileNode from kallithea.lib.vcs.utils.compat import unittest -from kallithea.tests.vcs.base import BackendTestMixin +from kallithea.tests.vcs.base import _BackendTestMixin from kallithea.tests.vcs.conf import SCM_TESTS -class WorkdirTestCaseMixin(BackendTestMixin): +class WorkdirTestCaseMixin(_BackendTestMixin): @classmethod def _get_commits(cls):