Skip to content

Commit 6dff687

Browse files
james-flynn-ieDonJayamanne
authored andcommitted
Feature/5603 update pytest on ui settings (#5787)
* Renaming pyTestArgs to pytestArgs * Renaming pyTestEnabled to pytestEnabled * Renaming pyTestPath to pytestPath * Adding news file for #5603 * Reverting case change for pytestargs defs/vars in pythonfiles * Adding check for old pyTestEnabled test settings * Adding pyTestEnabled check to fixSettingInFile() * Updating fixSettingInFile function to regex-replace 'pyTest' strings
1 parent ea4f035 commit 6dff687

26 files changed

Lines changed: 72 additions & 64 deletions

news/.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"python.jediEnabled": false,
33
"python.formatting.provider": "black",
44
"editor.formatOnSave": true,
5-
"python.testing.pyTestArgs": [
5+
"python.testing.pytestArgs": [
66
"."
77
],
88
"python.testing.unittestEnabled": false,
99
"python.testing.nosetestsEnabled": false,
10-
"python.testing.pyTestEnabled": true
10+
"python.testing.pytestEnabled": true
1111
}

news/1 Enhancements/5603.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updated labels in File > Preferences > Settings. It now states 'Pytest' where it stated 'Py Test'.
2+
(thanks [James Flynn](https://github.com/james-flynn-ie/))

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,7 @@
19471947
"description": "Prompt to configure a test framework if potential tests directories are discovered.",
19481948
"scope": "resource"
19491949
},
1950-
"python.testing.pyTestArgs": {
1950+
"python.testing.pytestArgs": {
19511951
"type": "array",
19521952
"description": "Arguments passed in. Each argument is a separate item in the array.",
19531953
"default": [],
@@ -1956,13 +1956,13 @@
19561956
},
19571957
"scope": "resource"
19581958
},
1959-
"python.testing.pyTestEnabled": {
1959+
"python.testing.pytestEnabled": {
19601960
"type": "boolean",
19611961
"default": false,
19621962
"description": "Enable testing using pytest.",
19631963
"scope": "resource"
19641964
},
1965-
"python.testing.pyTestPath": {
1965+
"python.testing.pytestPath": {
19661966
"type": "string",
19671967
"default": "pytest",
19681968
"description": "Path to pytest (pytest), you can use a custom version of pytest by modifying this setting to include the full path.",

src/client/application/diagnostics/checks/updateTestSettings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,14 @@ export class InvalidTestSettingDiagnosticsService extends BaseDiagnosticsService
107107
public async fixSettingInFile(filePath: string) {
108108
const fileContents = await this.fs.readFile(filePath);
109109
const setting = new RegExp('"python.unitTest', 'g');
110+
const setting_pytest_enabled = new RegExp('.pyTestEnabled"', 'g');
111+
const setting_pytest_args = new RegExp('.pyTestArgs"', 'g');
112+
const setting_pytest_path = new RegExp('.pyTestPath"', 'g');
110113

111114
await this.fs.writeFile(filePath, fileContents.replace(setting, '"python.testing'));
115+
await this.fs.writeFile(filePath, fileContents.replace(setting_pytest_enabled, '.pytestEnabled"'));
116+
await this.fs.writeFile(filePath, fileContents.replace(setting_pytest_args, '.pytestArgs"'));
117+
await this.fs.writeFile(filePath, fileContents.replace(setting_pytest_path, '.pytestPath"'));
112118

113119
// Keep track of updated file.
114120
this.stateStore.value.push(filePath);
@@ -124,7 +130,7 @@ export class InvalidTestSettingDiagnosticsService extends BaseDiagnosticsService
124130
return false;
125131
}
126132
const contents = await this.fs.readFile(filePath);
127-
return contents.indexOf('python.unitTest.') > 0;
133+
return contents.indexOf('python.unitTest.') > 0 || contents.indexOf('python.pyTest') > 0;
128134
}
129135
/**
130136
* Checks whether to handle a particular workspace resource.

src/client/common/configSettings.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,10 @@ export class PythonSettings implements IPythonSettings {
304304
// tslint:disable-next-line:prefer-type-cast
305305
// tslint:disable-next-line:no-object-literal-type-assertion
306306
this.testing = {
307-
nosetestArgs: [], pyTestArgs: [], unittestArgs: [],
307+
nosetestArgs: [], pytestArgs: [], unittestArgs: [],
308308
promptToConfigure: true, debugPort: 3000,
309-
nosetestsEnabled: false, pyTestEnabled: false, unittestEnabled: false,
310-
nosetestPath: 'nosetests', pyTestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true
309+
nosetestsEnabled: false, pytestEnabled: false, unittestEnabled: false,
310+
nosetestPath: 'nosetests', pytestPath: 'pytest', autoTestDiscoverOnSaveEnabled: true
311311
} as ITestingSettings;
312312
}
313313
}
@@ -317,18 +317,18 @@ export class PythonSettings implements IPythonSettings {
317317
promptToConfigure: true,
318318
debugPort: 3000,
319319
nosetestArgs: [], nosetestPath: 'nosetest', nosetestsEnabled: false,
320-
pyTestArgs: [], pyTestEnabled: false, pyTestPath: 'pytest',
320+
pytestArgs: [], pytestEnabled: false, pytestPath: 'pytest',
321321
unittestArgs: [], unittestEnabled: false, autoTestDiscoverOnSaveEnabled: true
322322
};
323-
this.testing.pyTestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pyTestPath), workspaceRoot);
323+
this.testing.pytestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.pytestPath), workspaceRoot);
324324
this.testing.nosetestPath = getAbsolutePath(systemVariables.resolveAny(this.testing.nosetestPath), workspaceRoot);
325325
if (this.testing.cwd) {
326326
this.testing.cwd = getAbsolutePath(systemVariables.resolveAny(this.testing.cwd), workspaceRoot);
327327
}
328328

329329
// Resolve any variables found in the test arguments.
330330
this.testing.nosetestArgs = this.testing.nosetestArgs.map(arg => systemVariables.resolveAny(arg));
331-
this.testing.pyTestArgs = this.testing.pyTestArgs.map(arg => systemVariables.resolveAny(arg));
331+
this.testing.pytestArgs = this.testing.pytestArgs.map(arg => systemVariables.resolveAny(arg));
332332
this.testing.unittestArgs = this.testing.unittestArgs.map(arg => systemVariables.resolveAny(arg));
333333

334334
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion

src/client/common/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ export interface ITestingSettings {
179179
readonly nosetestsEnabled: boolean;
180180
nosetestPath: string;
181181
nosetestArgs: string[];
182-
readonly pyTestEnabled: boolean;
183-
pyTestPath: string;
184-
pyTestArgs: string[];
182+
readonly pytestEnabled: boolean;
183+
pytestPath: string;
184+
pytestArgs: string[];
185185
readonly unittestEnabled: boolean;
186186
unittestArgs: string[];
187187
cwd?: string;

src/client/testing/common/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function getExecutablePath(testProvider: TestProvider, settings: IPythonSettings
9090
break;
9191
}
9292
case PYTEST_PROVIDER: {
93-
testRunnerExecutablePath = settings.testing.pyTestPath;
93+
testRunnerExecutablePath = settings.testing.pytestPath;
9494
break;
9595
}
9696
default: {

src/client/testing/common/services/configSettingService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class TestConfigSettingsService implements ITestConfigSettingsService {
3131
case Product.unittest:
3232
return 'testing.unittestArgs';
3333
case Product.pytest:
34-
return 'testing.pyTestArgs';
34+
return 'testing.pytestArgs';
3535
case Product.nosetest:
3636
return 'testing.nosetestArgs';
3737
default:
@@ -43,7 +43,7 @@ export class TestConfigSettingsService implements ITestConfigSettingsService {
4343
case Product.unittest:
4444
return 'testing.unittestEnabled';
4545
case Product.pytest:
46-
return 'testing.pyTestEnabled';
46+
return 'testing.pytestEnabled';
4747
case Product.nosetest:
4848
return 'testing.nosetestsEnabled';
4949
default:

src/client/testing/common/services/testManagerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TestManagerService implements ITestManagerService {
4040
const settings = this.configurationService.getSettings(this.wkspace);
4141
if (settings.testing.nosetestsEnabled) {
4242
return Product.nosetest;
43-
} else if (settings.testing.pyTestEnabled) {
43+
} else if (settings.testing.pytestEnabled) {
4444
return Product.pytest;
4545
} else if (settings.testing.unittestEnabled) {
4646
return Product.unittest;

src/client/testing/common/testUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export class TestsHelper implements ITestsHelper {
9191
switch (id) {
9292
case 'pytest': {
9393
return {
94-
argsName: 'pyTestArgs' as keyof ITestingSettings,
95-
pathName: 'pyTestPath' as keyof ITestingSettings,
96-
enabledName: 'pyTestEnabled' as keyof ITestingSettings
94+
argsName: 'pytestArgs' as keyof ITestingSettings,
95+
pathName: 'pytestPath' as keyof ITestingSettings,
96+
enabledName: 'pytestEnabled' as keyof ITestingSettings
9797
};
9898
}
9999
case 'nosetest': {

0 commit comments

Comments
 (0)