Skip to content

Commit 12c2c73

Browse files
Python: Enable Gradle build cache and Develocity test reporting for pytest (#6819)
Add output declarations, path sensitivity, and cacheIf to the pytestTest task so it participates in the remote build cache. Register the JUnit XML report with Develocity via ImportJUnitXmlReports so pytest results appear in build scans.
1 parent fc90cc8 commit 12c2c73

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

rewrite-python/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@file:Suppress("UnstableApiUsage")
22

3+
import com.gradle.develocity.agent.gradle.test.ImportJUnitXmlReports
4+
import com.gradle.develocity.agent.gradle.test.JUnitXmlDialect
35
import nl.javadude.gradle.plugins.license.LicenseExtension
46
import java.time.LocalDateTime
57
import java.time.format.DateTimeFormatter
@@ -163,13 +165,21 @@ val pytestTest by tasks.registering(Exec::class) {
163165
dependsOn(pythonInstall)
164166

165167
workingDir = pythonDir
166-
commandLine(pythonExe.absolutePath, "-m", "pytest", "tests/", "-v")
168+
commandLine(pythonExe.absolutePath, "-m", "pytest", "tests/", "-v",
169+
"--junitxml=build/test-results/pytest/junit.xml")
167170

168171
inputs.dir(pythonDir.resolve("src"))
172+
.withPathSensitivity(PathSensitivity.RELATIVE)
169173
inputs.dir(pythonDir.resolve("tests"))
174+
.withPathSensitivity(PathSensitivity.RELATIVE)
170175
inputs.file(pythonDir.resolve("pyproject.toml"))
176+
.withPathSensitivity(PathSensitivity.RELATIVE)
177+
outputs.file(pythonDir.resolve("build/test-results/pytest/junit.xml"))
178+
outputs.cacheIf { true }
171179
}
172180

181+
ImportJUnitXmlReports.register(tasks, pytestTest, JUnitXmlDialect.GENERIC)
182+
173183
tasks.named("check") {
174184
dependsOn(testing.suites.named("py2CompatibilityTest"))
175185
dependsOn(pytestTest)

0 commit comments

Comments
 (0)