Skip to content

Commit

Permalink
fix: checking unittest framework exists can be slow
Browse files Browse the repository at this point in the history
Sometimes importing a test framework such as pytest can trigger
importing other code that has a longer runtime on import than allowed by
the spawned process. This fixes the issue by checking that the import
path can be found, which does not trigger importing the code.
  • Loading branch information
aghoward committed Feb 12, 2025
1 parent ab6975f commit 0ff697c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const framework = workspace.getConfiguration('pyright').get<TestingFramework>('t

function validPythonModule(pythonPath: string, moduleName: string) {
try {
const pythonProcess = child_process.spawnSync(pythonPath, ['-m', moduleName, '--help'], { encoding: 'utf8' });
const pythonProcess = child_process.spawnSync(pythonPath, ['-c', `from importlib.machinery import PathFinder; assert PathFinder.find_spec("${moduleName}") is not None`], { encoding: 'utf8' });
if (pythonProcess.error) return false;
return pythonProcess.status === 0;
} catch (ex) {
Expand Down

0 comments on commit 0ff697c

Please sign in to comment.