forked from mercadona/rele
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
60 lines (43 loc) · 1.41 KB
/
runtests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8
from __future__ import absolute_import, unicode_literals
import os
import sys
from unittest.mock import patch
import django
from rele.apps import ReleConfig
class PytestTestRunner(object):
"""Runs pytest to discover and run tests."""
def __init__(self, verbosity=1, failfast=False, keepdb=False, **kwargs):
self.verbosity = verbosity
self.failfast = failfast
self.keepdb = keepdb
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)
def run_tests(*test_args):
if not test_args:
test_args = ["tests"]
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
with patch.object(ReleConfig, "ready"):
django.setup()
test_runner = PytestTestRunner()
failures = test_runner.run_tests(test_args)
sys.exit(bool(failures))
if __name__ == "__main__":
run_tests(*sys.argv[1:])