This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2020-09-11 21:21:11 +00:00
|
|
|
"""Integrate ./manage.py test with pytest"""
|
|
|
|
from django.conf import settings
|
|
|
|
|
2020-10-22 11:55:37 +00:00
|
|
|
from passbook.lib.config import CONFIG
|
|
|
|
|
2020-09-11 21:21:11 +00:00
|
|
|
|
|
|
|
class PytestTestRunner:
|
|
|
|
"""Runs pytest to discover and run tests."""
|
|
|
|
|
|
|
|
def __init__(self, verbosity=1, failfast=False, keepdb=False, **_):
|
|
|
|
self.verbosity = verbosity
|
|
|
|
self.failfast = failfast
|
|
|
|
self.keepdb = keepdb
|
|
|
|
settings.TEST = True
|
|
|
|
settings.CELERY_TASK_ALWAYS_EAGER = True
|
2020-10-22 11:55:37 +00:00
|
|
|
CONFIG.raw.get("passbook")["avatars"] = "none"
|
2020-09-11 21:21:11 +00:00
|
|
|
|
|
|
|
def run_tests(self, test_labels):
|
|
|
|
"""Run pytest and return the exitcode.
|
|
|
|
|
|
|
|
It translates some of Django's test command option to pytest's.
|
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
argv = []
|
|
|
|
if self.verbosity == 0:
|
|
|
|
argv.append("--quiet")
|
|
|
|
if self.verbosity == 2:
|
|
|
|
argv.append("--verbose")
|
|
|
|
if self.verbosity == 3:
|
|
|
|
argv.append("-vv")
|
|
|
|
if self.failfast:
|
|
|
|
argv.append("--exitfirst")
|
|
|
|
if self.keepdb:
|
|
|
|
argv.append("--reuse-db")
|
|
|
|
|
|
|
|
argv.extend(test_labels)
|
|
|
|
return pytest.main(argv)
|