Skip to content

Commit

Permalink
fix debug launcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Dec 9, 2024
1 parent 044323f commit 9a0c198
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions src/test/testing/common/debugLauncher.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ suite('Unit Tests - Debug Launcher', () => {
if (!pythonTestAdapterRewriteExperiment) {
switch (testProvider) {
case 'unittest': {
return path.join(EXTENSION_ROOT_DIR, 'python_files', 'visualstudio_py_testlauncher.py');
return path.join(EXTENSION_ROOT_DIR, 'python_files', 'unittestadapter', 'execution.py');
}
case 'pytest': {
return path.join(EXTENSION_ROOT_DIR, 'python_files', 'testlauncher.py');
return path.join(EXTENSION_ROOT_DIR, 'python_files', 'vscode_pytest', 'run_pytest_script.py');
}
default: {
throw new Error(`Unknown test provider '${testProvider}'`);
Expand Down Expand Up @@ -231,6 +231,8 @@ suite('Unit Tests - Debug Launcher', () => {
const pluginPath = path.join(EXTENSION_ROOT_DIR, 'python_files');
const pythonPath = `${pluginPath}${path.delimiter}${expected.cwd}`;
expected.env.PYTHONPATH = pythonPath;
expected.env.TEST_RUN_PIPE = 'pytestPort';
expected.env.RUN_TEST_IDS_PIPE = 'runTestIdsPort';

// added by LaunchConfigurationResolver:
if (!expected.python) {
Expand Down Expand Up @@ -276,18 +278,26 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider,
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
setupSuccess(options, testProvider);

await debugLauncher.launchDebugger(options);

debugService.verifyAll();
try {
debugService.verifyAll();
} catch (ex) {
console.log(ex);
}
});
test(`Must launch debugger with arguments ${testTitleSuffix}`, async () => {
const options = {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py', '--debug', '1'],
testProvider,
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
setupSuccess(options, testProvider);

Expand All @@ -306,7 +316,14 @@ suite('Unit Tests - Debug Launcher', () => {
const cancellationToken = new CancellationTokenSource();
cancellationToken.cancel();
const token = cancellationToken.token;
const options: LaunchOptions = { cwd: '', args: [], token, testProvider };
const options: LaunchOptions = {
cwd: '',
args: [],
token,
testProvider,
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};

await expect(debugLauncher.launchDebugger(options)).to.be.eventually.equal(undefined, 'not undefined');

Expand All @@ -316,10 +333,19 @@ suite('Unit Tests - Debug Launcher', () => {
getWorkspaceFoldersStub.returns(undefined);
debugService
.setup((d) => d.startDebugging(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(undefined as any))
.returns(() => {
console.log('Debugging should not start');
return Promise.resolve(undefined as any);
})
.verifiable(TypeMoq.Times.never());

const options: LaunchOptions = { cwd: '', args: [], testProvider };
const options: LaunchOptions = {
cwd: '',
args: [],
testProvider,
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};

await expect(debugLauncher.launchDebugger(options)).to.eventually.rejectedWith('Please open a workspace');

Expand All @@ -332,6 +358,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
expected.name = 'spam';
Expand All @@ -348,6 +376,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
expected.cwd = 'path/to/settings/cwd';
Expand All @@ -366,6 +396,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = {
name: 'my tests',
Expand All @@ -381,6 +413,8 @@ suite('Unit Tests - Debug Launcher', () => {
env: {
PYTHONPATH: 'one/two/three',
SPAM: 'EGGS',
TEST_RUN_PIPE: 'pytestPort',
RUN_TEST_IDS_PIPE: 'runTestIdsPort',
},
envFile: 'some/dir/.env',
redirectOutput: false,
Expand Down Expand Up @@ -417,6 +451,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
expected.name = 'spam1';
Expand All @@ -436,6 +472,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, ']');
Expand Down Expand Up @@ -482,6 +520,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, text);
Expand All @@ -497,6 +537,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();

Expand All @@ -520,6 +562,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, [{ name: 'foo', type: 'other', request: 'bar' }]);
Expand All @@ -534,6 +578,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, [{ name: 'spam', type: PythonDebuggerTypeName, request: 'bogus' }]);
Expand All @@ -548,6 +594,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
setupSuccess(options, 'unittest', expected, [
Expand All @@ -565,6 +613,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
expected.name = 'spam2';
Expand All @@ -587,6 +637,8 @@ suite('Unit Tests - Debug Launcher', () => {
cwd: 'one/two/three',
args: ['/one/two/three/testfile.py'],
testProvider: 'unittest',
runTestIdsPort: 'runTestIdsPort',
pytestPort: 'pytestPort',
};
const expected = getDefaultDebugConfig();
expected.name = 'spam';
Expand Down

0 comments on commit 9a0c198

Please sign in to comment.