1717
1818import com .linkedin .gradle .python .PythonExtension ;
1919import com .linkedin .gradle .python .extension .MypyExtension ;
20+ import com .linkedin .gradle .python .extension .CoverageExtension ;
2021import com .linkedin .gradle .python .tasks .AbstractPythonMainSourceDefaultTask ;
2122import com .linkedin .gradle .python .tasks .AbstractPythonTestSourceDefaultTask ;
2223import com .linkedin .gradle .python .tasks .CheckStyleGeneratorTask ;
@@ -72,8 +73,20 @@ public void apply(final Project project) {
7273 *
7374 * This uses the ``setup.cfg`` if present to configure py.test.
7475 */
76+ CoverageExtension cov = ExtensionUtils .maybeCreate (project , "coverage" , CoverageExtension .class );
7577 project .getTasks ().create (TASK_COVERAGE .getValue (), PyCoverageTask .class ,
76- task -> task .onlyIf (it -> project .file (settings .testDir ).exists ()));
78+ task -> task .onlyIf (it -> project .file (settings .testDir ).exists ()
79+ /* The test suite and other environments run
80+ * the coverage task explicitly, so check
81+ * whether the flag is set *or* its been
82+ * explicitly invoked.
83+ */
84+ && (cov .isRun () || project .getGradle ().getStartParameter ().getTaskNames ().contains ("coverage" ))
85+ ));
86+
87+ // Make task "check" depend on coverage task.
88+ project .getTasks ().getByName (TASK_CHECK .getValue ())
89+ .dependsOn (project .getTasks ().getByName (TASK_COVERAGE .getValue ()));
7790
7891 /*
7992 * Run flake8.
@@ -92,7 +105,7 @@ public void apply(final Project project) {
92105 project .getTasks ().create (TASK_MYPY .getValue (), MypyTask .class ,
93106 task -> task .onlyIf (it -> project .file (settings .srcDir ).exists () && mypy .isRun ()));
94107
95- // Make task "check" depend on mypy task
108+ // Make task "check" depend on mypy task.
96109 project .getTasks ().getByName (TASK_CHECK .getValue ())
97110 .dependsOn (project .getTasks ().getByName (TASK_MYPY .getValue ()));
98111
0 commit comments