• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 19015773527

02 Nov 2025 05:33PM UTC coverage: 17.872% (-62.4%) from 80.3%
19015773527

Pull #22816

github

web-flow
Merge a12d75757 into 6c024e162
Pull Request #22816: Update Pants internal Python to 3.14

4 of 5 new or added lines in 3 files covered. (80.0%)

28452 existing lines in 683 files now uncovered.

9831 of 55007 relevant lines covered (17.87%)

0.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/python/pants/backend/go/subsystems/gotest.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

UNCOV
4
from __future__ import annotations
×
5

UNCOV
6
import os
×
UNCOV
7
from pathlib import PurePath
×
8

UNCOV
9
from pants.backend.go.target_types import (
×
10
    GoAddressSanitizerEnabledField,
11
    GoMemorySanitizerEnabledField,
12
    GoPackageTarget,
13
    GoTestRaceDetectorEnabledField,
14
)
UNCOV
15
from pants.backend.go.util_rules.coverage import GoCoverMode
×
UNCOV
16
from pants.build_graph.address import Address
×
UNCOV
17
from pants.core.util_rules.distdir import DistDir
×
UNCOV
18
from pants.option.option_types import (
×
19
    ArgsListOption,
20
    BoolOption,
21
    EnumOption,
22
    SkipOption,
23
    StrListOption,
24
    StrOption,
25
)
UNCOV
26
from pants.option.subsystem import Subsystem
×
UNCOV
27
from pants.util.strutil import softwrap
×
28

29

UNCOV
30
class GoTestSubsystem(Subsystem):
×
UNCOV
31
    options_scope = "go-test"
×
UNCOV
32
    name = "Go test binary"
×
UNCOV
33
    help = "Options for Go tests."
×
34

UNCOV
35
    args = ArgsListOption(
×
36
        example="-run TestFoo -v",
37
        extra_help=softwrap(
38
            """
39
            Known Go test options will be transformed into the form expected by the test
40
            binary, e.g. `-v` becomes `-test.v`. Run `go help testflag` from the Go SDK to
41
            learn more about the options supported by Go test binaries.
42
            """
43
        ),
44
        passthrough=True,
45
    )
46

UNCOV
47
    coverage_mode = EnumOption(
×
48
        "--cover-mode",
49
        default=GoCoverMode.SET,
50
        help=softwrap(
51
            """\
52
            Coverage mode to use when running Go tests with coverage analysis enabled via `--test-use-coverage`.
53
            Valid values are `set`, `count`, and `atomic`:
54

55
              * `set`: bool: does this statement run?
56
              * `count`: int: how many times does this statement run?
57
              * `atomic`: int: count, but correct in multithreaded tests; significantly more expensive.
58
            """
59
        ),
60
    )
61

UNCOV
62
    _coverage_output_dir = StrOption(
×
63
        default=str(PurePath("{distdir}", "coverage", "go", "{target_spec}")),
64
        advanced=True,
65
        help=softwrap(
66
            """
67
            Path to write the Go coverage reports to. Must be relative to the build root.
68

69
            Replacements:
70

71
              - `{distdir}` is replaced with the Pants `distdir`.
72
              - `{target_spec}` is replaced with the address of the applicable `go_package` target with `/`
73
              characters replaced with dots (`.`).
74
              - `{import_path}` is replaced with the applicable package's import path. Subdirectories will be made
75
              for any path components separated by `/` characters.
76
              - `{import_path_escaped}` is replaced with the applicable package's import path but with
77
              slashes converted to underscores. This is deprecated and only exists to support behavior from
78
              earlier versions.
79
            """
80
        ),
81
    )
82

UNCOV
83
    coverage_html = BoolOption(
×
84
        default=True,
85
        help=softwrap(
86
            """
87
            If true, then convert coverage reports to HTML format and write a `coverage.html` file next to the
88
            raw coverage data.
89
            """
90
        ),
91
    )
92

UNCOV
93
    coverage_packages = StrListOption(
×
94
        default=[],
95
        help=softwrap(
96
            """
97
            A list of "import path patterns" for determining which import paths will be instrumented for code
98
            coverage.
99

100
            From `go help packages`:
101

102
            An import path is a pattern if it includes one or more "..." wildcards,
103
            each of which can match any string, including the empty string and
104
            strings containing slashes. Such a pattern expands to all package
105
            directories found in the GOPATH trees with names matching the
106
            patterns.
107

108
            To make common patterns more convenient, there are two special cases.
109
            First, /... at the end of the pattern can match an empty string,
110
            so that net/... matches both net and packages in its subdirectories, like net/http.
111
            Second, any slash-separated pattern element containing a wildcard never
112
            participates in a match of the "vendor" element in the path of a vendored
113
            package, so that ./... does not match packages in subdirectories of
114
            ./vendor or ./mycode/vendor, but ./vendor/... and ./mycode/vendor/... do.
115
            Note, however, that a directory named vendor that itself contains code
116
            is not a vendored package: cmd/vendor would be a command named vendor,
117
            and the pattern cmd/... matches it.
118
            See golang.org/s/go15vendor for more about vendoring.
119

120
            This option is similar to the `go test -coverpkg` option, but without support currently
121
            for reserved import path patterns like `std` and `all`.
122
            """
123
        ),
124
    )
125

UNCOV
126
    skip = SkipOption("test")
×
127

UNCOV
128
    force_race = BoolOption(
×
129
        default=False,
130
        help=softwrap(
131
            f"""
132
            If true, then always enable the Go data race detector when running tests regardless of the
133
            test-by-test `{GoTestRaceDetectorEnabledField.alias}` field on the relevant `{GoPackageTarget.alias}`
134
            target.
135

136
            See https://go.dev/doc/articles/race_detector for additional information about the Go data race detector.
137
            """
138
        ),
139
    )
140

UNCOV
141
    force_msan = BoolOption(
×
142
        default=False,
143
        help=softwrap(
144
            f"""
145
            If true, then always enable interoperation between Go and the C/C++ "memory sanitizer" when running tests
146
            regardless of the test-by-test `{GoMemorySanitizerEnabledField.alias}` field on the relevant
147
            `{GoPackageTarget.alias}` target.
148

149
            See https://github.com/google/sanitizers/wiki/MemorySanitizer for additional information about
150
            the C/C++ memory sanitizer.
151
            """
152
        ),
153
    )
154

UNCOV
155
    force_asan = BoolOption(
×
156
        default=False,
157
        help=softwrap(
158
            f"""
159
            If true, then always enable interoperation between Go and the C/C++ "address sanitizer" when running tests
160
            regardless of the test-by-test `{GoAddressSanitizerEnabledField.alias}` field on the relevant
161
            `{GoPackageTarget.alias}` target.
162

163
            See https://github.com/google/sanitizers/wiki/AddressSanitizer for additional information about
164
            the C/C++ address sanitizer.
165
            """
166
        ),
167
    )
168

UNCOV
169
    block_profile = BoolOption(
×
170
        default=False,
171
        help=softwrap(
172
            """
173
            Capture a goroutine blocking profile from the execution of the test runner. The profile will be written
174
            to the file `block.out` in the test extra output directory. The test binary will also be written to
175
            the test extra output directory.
176

177
            """
178
        ),
179
    )
180

UNCOV
181
    cpu_profile = BoolOption(
×
182
        default=False,
183
        help=softwrap(
184
            """
185
            Capture a CPU profile from the execution of the test runner. The profile will be written to the
186
            file `cpu.out` in the test extra output directory. The test binary will also be written to the
187
            test extra output directory.
188
            """
189
        ),
190
    )
191

UNCOV
192
    mem_profile = BoolOption(
×
193
        default=False,
194
        help=softwrap(
195
            """
196
            Capture an allocation profile from the execution of the test runner after tests have passed.
197
            The profile will be written to the file `mem.out` in the test extra output directory.
198
            The test binary will also be written to the test extra output directory.
199
            """
200
        ),
201
    )
202

UNCOV
203
    mutex_profile = BoolOption(
×
204
        default=False,
205
        help=softwrap(
206
            """
207
            Capture a mutex contention profile from the execution of the test runner when all tests are
208
            complete. The profile will be written to the file `mutex.out` in the test extra output directory.
209
            The test binary will also be written to the test extra output directory.
210
            """
211
        ),
212
    )
213

UNCOV
214
    trace = BoolOption(
×
215
        default=False,
216
        help=softwrap(
217
            """
218
            Capture an execution trace from the execution of the test runner. The trace will be written to the
219
            file `trace.out` in the test extra output directory.
220
            """
221
        ),
222
    )
223

UNCOV
224
    output_test_binary = BoolOption(
×
225
        default=False,
226
        help=softwrap(
227
            """
228
            Write the test binary to the test extra output directory.
229

230
            This is similar to the `go test -c` option, but will still run the underlying test.
231
            """
232
        ),
233
        advanced=True,
234
    )
235

UNCOV
236
    def coverage_output_dir(self, distdir: DistDir, address: Address, import_path: str) -> PurePath:
×
237
        target_spec = address.spec_path.replace(os.sep, ".")
×
238
        import_path_escaped = import_path.replace("/", "_")
×
239
        return PurePath(
×
240
            self._coverage_output_dir.format(
241
                distdir=distdir.relpath,
242
                target_spec=target_spec,
243
                import_path=import_path,
244
                import_path_escaped=import_path_escaped,
245
            )
246
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc