Mercurial > kallithea
changeset 7214:22e80164295f
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.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Fri, 16 Mar 2018 21:44:08 +0100 |
parents | 01b58775d719 |
children | 8a1caf0f2592 |
files | kallithea/tests/vcs/base.py |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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)