Skip to content

Commit 32d1f5b

Browse files
committed
Fix pytest installation (#1912)
1 parent 67423d2 commit 32d1f5b

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python/PythonGenerateTestsCommand.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ class PythonGenerateTestsCommand : CliktCommand(
252252
installingRequirementsAction = {
253253
logger.info("Installing requirements...")
254254
},
255-
testFrameworkInstallationAction = {
256-
logger.info("Test framework installation...")
257-
},
258255
requirementsAreNotInstalledAction = ::processMissingRequirements,
259256
startedLoadingPythonTypesAction = {
260257
logger.info("Loading information about Python types...")

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ object PythonDialogProcessor {
166166
}
167167
try {
168168
val methods = findSelectedPythonMethods(model)
169+
val requirementsList = requirements.toMutableList()
170+
if (!model.testFramework.isInstalled) {
171+
requirementsList += model.testFramework.mainPackage
172+
}
169173

170174
processTestGeneration(
171175
pythonPath = model.pythonPath,
@@ -185,9 +189,8 @@ object PythonDialogProcessor {
185189
isCanceled = { indicator.isCanceled },
186190
checkingRequirementsAction = { indicator.text = "Checking requirements" },
187191
installingRequirementsAction = { indicator.text = "Installing requirements..." },
188-
testFrameworkInstallationAction = { indicator.text = "Test framework installation" },
189192
requirementsAreNotInstalledAction = {
190-
askAndInstallRequirementsLater(model.project, model.pythonPath)
193+
askAndInstallRequirementsLater(model.project, model.pythonPath, requirementsList)
191194
PythonTestGenerationProcessor.MissingRequirementsActionResult.NOT_INSTALLED
192195
},
193196
startedLoadingPythonTypesAction = { indicator.text = "Loading information about Python types" },
@@ -245,11 +248,11 @@ object PythonDialogProcessor {
245248
}
246249
}
247250

248-
private fun askAndInstallRequirementsLater(project: Project, pythonPath: String) {
251+
private fun askAndInstallRequirementsLater(project: Project, pythonPath: String, requirementsList: List<String>) {
249252
val message = """
250253
Some requirements are not installed.
251254
Requirements: <br>
252-
${requirements.joinToString("<br>")}
255+
${requirementsList.joinToString("<br>")}
253256
<br>
254257
Install them?
255258
""".trimIndent()
@@ -267,15 +270,15 @@ object PythonDialogProcessor {
267270

268271
ProgressManager.getInstance().run(object : Backgroundable(project, "Installing requirements") {
269272
override fun run(indicator: ProgressIndicator) {
270-
val installResult = installRequirements(pythonPath)
273+
val installResult = installRequirements(pythonPath, requirementsList)
271274

272275
if (installResult.exitValue != 0) {
273276
showErrorDialogLater(
274277
project,
275278
"Requirements installing failed.<br>" +
276279
"${installResult.stderr}<br><br>" +
277280
"Try to install with pip:<br>" +
278-
" ${requirements.joinToString("<br>")}",
281+
" ${requirementsList.joinToString("<br>")}",
279282
"Requirements error"
280283
)
281284
}

utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package org.utbot.python
22

33
import com.squareup.moshi.Moshi
44
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
5-
import mu.KotlinLogging
65
import org.parsers.python.PythonParser
76
import org.utbot.python.framework.codegen.model.PythonSysPathImport
87
import org.utbot.python.framework.codegen.model.PythonSystemImport
98
import org.utbot.python.framework.codegen.model.PythonUserImport
109
import org.utbot.framework.codegen.domain.TestFramework
1110
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
1211
import org.utbot.framework.plugin.api.ExecutableId
13-
import org.utbot.framework.plugin.api.TimeoutException
1412
import org.utbot.framework.plugin.api.UtClusterInfo
1513
import org.utbot.framework.plugin.api.UtExecutionSuccess
1614
import org.utbot.framework.plugin.api.util.UtContext
@@ -30,15 +28,12 @@ import org.utbot.python.newtyping.mypy.readMypyAnnotationStorageAndInitialErrors
3028
import org.utbot.python.newtyping.mypy.setConfigFile
3129
import org.utbot.python.typing.MypyAnnotations
3230
import org.utbot.python.utils.Cleaner
33-
import org.utbot.python.utils.RequirementsUtils.installRequirements
3431
import org.utbot.python.utils.RequirementsUtils.requirementsAreInstalled
3532
import org.utbot.python.utils.getLineOfFunction
3633
import java.nio.file.Path
3734
import kotlin.io.path.Path
3835
import kotlin.io.path.pathString
3936

40-
private val logger = KotlinLogging.logger {}
41-
4237
object PythonTestGenerationProcessor {
4338
fun processTestGeneration(
4439
pythonPath: String,
@@ -58,7 +53,6 @@ object PythonTestGenerationProcessor {
5853
isCanceled: () -> Boolean = { false },
5954
checkingRequirementsAction: () -> Unit = {},
6055
installingRequirementsAction: () -> Unit = {},
61-
testFrameworkInstallationAction: () -> Unit = {},
6256
requirementsAreNotInstalledAction: () -> MissingRequirementsActionResult = {
6357
MissingRequirementsActionResult.NOT_INSTALLED
6458
},
@@ -73,10 +67,6 @@ object PythonTestGenerationProcessor {
7367
Cleaner.restart()
7468

7569
try {
76-
if (!testFramework.isInstalled) {
77-
testFrameworkInstallationAction()
78-
installRequirements(pythonPath, listOf(testFramework.mainPackage))
79-
}
8070
if (!doNotCheckRequirements) {
8171
checkingRequirementsAction()
8272
if (!requirementsAreInstalled(pythonPath)) {

0 commit comments

Comments
 (0)