Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/11264.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow user modules import when discovering tests.
4 changes: 3 additions & 1 deletion src/client/testing/unittest/services/discoveryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class TestDiscoveryService implements ITestDiscoveryService {
const pythonScript = this.getDiscoveryScript(options);
const unitTestOptions = this.translateOptions(options);
const runOptions: Options = {
args: internalPython.execCode(pythonScript),
// unittest needs to load modules in the workspace
// isolating it breaks unittest discovery
args: internalPython.execCode(pythonScript, false),
cwd: options.cwd,
workspaceFolder: options.workspaceFolder,
token: options.token,
Expand Down
24 changes: 12 additions & 12 deletions src/test/testing/unittest/unittest.discovery.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.contain(dir);
expect(opts.args[2]).to.not.contain('loader.discover("."');
expect(opts.args[1]).to.contain(dir);
expect(opts.args[1]).to.not.contain('loader.discover("."');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down Expand Up @@ -117,8 +117,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.contain(dir);
expect(opts.args[2]).to.not.contain('loader.discover("."');
expect(opts.args[1]).to.contain(dir);
expect(opts.args[1]).to.not.contain('loader.discover("."');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down Expand Up @@ -163,8 +163,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.not.contain(dir);
expect(opts.args[2]).to.contain('loader.discover("."');
expect(opts.args[1]).to.not.contain(dir);
expect(opts.args[1]).to.contain('loader.discover("."');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down Expand Up @@ -205,8 +205,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.contain(pattern);
expect(opts.args[2]).to.not.contain('test*.py');
expect(opts.args[1]).to.contain(pattern);
expect(opts.args[1]).to.not.contain('test*.py');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down Expand Up @@ -251,8 +251,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.contain(pattern);
expect(opts.args[2]).to.not.contain('test*.py');
expect(opts.args[1]).to.contain(pattern);
expect(opts.args[1]).to.not.contain('test*.py');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down Expand Up @@ -297,8 +297,8 @@ suite('Unit Tests - Unittest - Discovery', () => {
.setup((r) => r.run(typeMoq.It.isValue(UNITTEST_PROVIDER), typeMoq.It.isAny()))
.callback((_, opts: Options) => {
expect(opts.args).to.include('-c');
expect(opts.args[2]).to.not.contain(pattern);
expect(opts.args[2]).to.contain('test*.py');
expect(opts.args[1]).to.not.contain(pattern);
expect(opts.args[1]).to.contain('test*.py');
})
.returns(() => Promise.resolve(runOutput))
.verifiable(typeMoq.Times.once());
Expand Down
7 changes: 3 additions & 4 deletions src/test/testing/unittest/unittest.run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,10 @@ suite('Unit Tests - unittest - run with mocked process output', () => {
.create()) as MockProcessService;
procService.onExecObservable((_file, args, _options, callback) => {
if (
//args[0] is pyvsc-run-isolated.py.
args.length > 1 &&
args[1] === '-c' &&
args[2].includes('import unittest') &&
args[2].includes('loader = unittest.TestLoader()')
args[0] === '-c' &&
args[1].includes('import unittest') &&
args[1].includes('loader = unittest.TestLoader()')
) {
callback({
// Ensure any spaces added during code formatting or the like are removed
Expand Down