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
 
@@ -5,6 +5,7 @@ InMemoryChangeset class is working prope
 
import os
 
import time
 
import datetime
 
import pytest
 

	
 
from kallithea.lib import vcs
 
from kallithea.lib.vcs.nodes import FileNode
 
@@ -26,10 +27,6 @@ class _BackendTestMixin(object):
 
    recreate_repo_per_test = True
 

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

	
 
    @classmethod
 
    def _get_commits(cls):
 
        commits = [
 
            {
 
@@ -58,8 +55,10 @@ class _BackendTestMixin(object):
 
        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)
 

	
 
@@ -87,6 +86,7 @@ class _BackendTestMixin(object):
 
                                     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)