Changeset - 22e80164295f
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 8 years ago 2018-03-16 21:44:08
thomas.de_schampheleire@nokia.com
tests: vcs: use pytest fixtures instead of xUnit-style setup_method/setup_class

A subsequent commit will introduce parametrization of fixtures to avoid each
test class to be duplicated for every supported VCS explicitly.

But this concept does not mix with xUnit-style methods setup_class and
setup_method, because the latter are called much earlier than pytest
fixtures and thus cannot use variables set only later by a fixture.

Therefore, use a real fixture to set up the class and test methods.
1 file changed with 7 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/vcs/base.py
Show inline comments
 
@@ -2,12 +2,13 @@
 
Module providing backend independent mixin class. It requires that
 
InMemoryChangeset class is working properly at backend class.
 
"""
 
import os
 
import time
 
import datetime
 
import pytest
 

	
 
from kallithea.lib import vcs
 
from kallithea.lib.vcs.nodes import FileNode
 

	
 
from kallithea.tests.vcs.conf import get_new_dir
 

	
 
@@ -23,16 +24,12 @@ class _BackendTestMixin(object):
 
    - ``recreate_repo_per_test``: If set to ``False``, repo would NOT be created
 
      before every single test. Defaults to ``True``.
 
    """
 
    recreate_repo_per_test = True
 

	
 
    @classmethod
 
    def get_backend(cls):
 
        return vcs.get_backend(cls.backend_alias)
 

	
 
    @classmethod
 
    def _get_commits(cls):
 
        commits = [
 
            {
 
                'message': u'Initial commit',
 
                'author': u'Joe Doe <joe.doe@example.com>',
 
                'date': datetime.datetime(2010, 1, 1, 20),
 
@@ -55,14 +52,16 @@ class _BackendTestMixin(object):
 
                'removed': [],
 
            },
 
        ]
 
        return commits
 

	
 
    @classmethod
 
    def setup_class(cls):
 
        Backend = cls.get_backend()
 
    @pytest.fixture(autouse=True,
 
                    scope='class')
 
    def _configure_backend(cls, request):
 
        Backend = vcs.get_backend(cls.backend_alias)
 
        cls.backend_class = Backend
 
        cls.setup_repo(Backend)
 

	
 
    @classmethod
 
    def setup_empty_repo(cls, backend):
 
        repo_path = get_new_dir(str(time.time()))
 
@@ -84,9 +83,10 @@ class _BackendTestMixin(object):
 
                cls.imc.remove(FileNode(node.path))
 

	
 
            cls.tip = cls.imc.commit(message=unicode(commit['message']),
 
                                     author=unicode(commit['author']),
 
                                     date=commit['date'])
 

	
 
    def setup_method(self, method):
 
    @pytest.fixture(autouse=True)
 
    def _possibly_recreate_repo(self):
 
        if getattr(self, 'recreate_repo_per_test', False):
 
            self.setup_repo(self.backend_class)
0 comments (0 inline, 0 general)