# HG changeset patch # User Thomas De Schampheleire # Date 1521233048 -3600 # Node ID 22e80164295fa6feac64d9d3d71b12951c4e0c09 # Parent 01b58775d7195922a7a14b3bb592a92dc0030cf2 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. diff -r 01b58775d719 -r 22e80164295f kallithea/tests/vcs/base.py --- a/kallithea/tests/vcs/base.py Fri Mar 16 21:33:53 2018 +0100 +++ b/kallithea/tests/vcs/base.py Fri Mar 16 21:44:08 2018 +0100 @@ -5,6 +5,7 @@ import os import time import datetime +import pytest from kallithea.lib import vcs from kallithea.lib.vcs.nodes import FileNode @@ -26,10 +27,6 @@ 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 @@ 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 @@ 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)