Debian Codegraph @

tasks/test.py

raw symbols SCIP
1 # -*- coding: ascii -*-
2 #
3 # Copyright 2018 - 2025
4 # Andr\xe9 Malo or his licensors, as applicable
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 """
18 Test suite tasks
19 ~~~~~~~~~~~~~~~~
20
21 """
22
23 import os as _os
24
25 import invoke as _invoke
26
27 from . import _features
28 from . import pypi as _pypi
29 from ._inv import tasks as _tasks
30
31
32 @_tasks.optional(None, _features.python_tests)
33 @_invoke.task()
34 def local(
35 ctx,
36 new_first=False,
37 failed_first=False,
38 keep_going=False,
39 capture=False,
40 coverage=False,
41 coverage_report=True,
42 only=None,
43 ):
44 """
45 Run the unit test suite using py.test
46
47 Parameters:
48 new_first (bool):
49 Run tests from new files first. Default: false
50
51 failed_first (bool):
52 Run all tests, but run the last failures first. Default: false
53
54 keep_going (bool):
55 Keep going after a failure? Default: false
56
57 capture (bool):
58 Capture output? Default: false
59
60 coverage (bool):
61 Measure test coverage? Default: false
62
63 coverage_report (bool):
64 Emit coverage report? Only relevant if coverage is enabled.
65 Default: true
66
67 only (str):
68 Filter expression for tests to run
69 """
70 # pylint: disable = too-many-positional-arguments
71
72 cmd = [ctx.which("py.test")] + ctx.s(
73 "-vv --color=yes --doctest-modules --doctest-ignore-import-errors"
74 )
75 if new_first:
76 cmd += ["--nf"]
77 if failed_first:
78 cmd += ["--ff"]
79 if not keep_going:
80 cmd += ["--exitfirst"]
81 if not capture:
82 cmd += ["-s"]
83 if coverage:
84 cmd += ["--no-cov-on-fail", "--cov", ctx.package]
85 if coverage_report:
86 cmd += ["--cov-report=html", "--cov-report=term"]
87 else:
88 cmd += ["--cov-report="]
89 if only:
90 cmd += ["-k", only]
91
92 for ignored in ctx.test.ignore:
93 cmd += ["--ignore", ignored]
94
95 # cmd += [ctx.package.replace(".", "/")]
96 cmd += ["tests"]
97
98 with ctx.shell.root_dir():
99 ctx.run(ctx.c(cmd), echo=True)
100
101
102 @_tasks.optional(None, _features.tox_tests)
103 @_invoke.task(default=True)
104 def tox(ctx, rebuild=False, env=None, hashseed=None):
105 """
106 Run the test suite using tox
107
108 Parameters:
109 rebuild (bool):
110 Rebuild tox environment(s)? Default: false
111
112 env (str):
113 A single test environment to run. All environments are run otherwise.
114
115 hashseed (str):
116 The hashseed to use. Only specify as a debugging measure.
117 """
118 cmd = [ctx.which("tox")]
119 if rebuild:
120 cmd += ["-r"]
121 if env is not None:
122 cmd += ["-e", env]
123 if hashseed is not None:
124 cmd += ["--hashseed", hashseed]
125
126 with ctx.shell.root_dir():
127 ctx.run(
128 ctx.c(cmd),
129 env=dict(_os.environ, PIP_INDEX_URL=_pypi.index_url(ctx)),
130 echo=True,
131 )