( args: RunTestArgs, pythonEnv: PythonEnvironment, )
| 243 | } |
| 244 | |
| 245 | async function runTestAtLocation( |
| 246 | args: RunTestArgs, |
| 247 | pythonEnv: PythonEnvironment, |
| 248 | ): Promise<void> { |
| 249 | const uri = parseUri(args.uri); |
| 250 | if (!uri) { |
| 251 | return; |
| 252 | } |
| 253 | const cwd = args.cwd; |
| 254 | const className = args.className; |
| 255 | const testName = args.testName; |
| 256 | |
| 257 | if (args.position && !testName && !className) { |
| 258 | await runAtCursor(uri, args.position); |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | const interpreter = await pythonEnv.getInterpreterPath(uri); |
| 263 | if (!interpreter) { |
| 264 | void showRunnableCodeLensError( |
| 265 | uri, |
| 266 | 'missing-interpreter', |
| 267 | 'Pyrefly could not determine a Python interpreter for this file. Ensure the correct interpreter is selected in your IDE before using runnable CodeLens.', |
| 268 | ); |
| 269 | return; |
| 270 | } |
| 271 | if (args.isUnittest === true) { |
| 272 | const moduleName = moduleNameFromPath(uri); |
| 273 | if (!moduleName) { |
| 274 | if (args.position) { |
| 275 | await runAtCursor(uri, args.position); |
| 276 | } |
| 277 | return; |
| 278 | } |
| 279 | let target = moduleName; |
| 280 | if (className) { |
| 281 | target = `${target}.${className}`; |
| 282 | } |
| 283 | if (testName) { |
| 284 | target = `${target}.${testName}`; |
| 285 | } |
| 286 | await executeProcessTask( |
| 287 | uri, |
| 288 | cwd, |
| 289 | {type: TASK_SOURCE, action: 'runUnittest'}, |
| 290 | 'Pyrefly: Run Test', |
| 291 | interpreter, |
| 292 | ['-m', 'unittest', target], |
| 293 | ); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | let nodeId = uri.fsPath; |
| 298 | if (className) { |
| 299 | nodeId = `${nodeId}::${className}`; |
| 300 | } |
| 301 | if (testName) { |
| 302 | nodeId = `${nodeId}::${testName}`; |
no test coverage detected