Skip to content

Commit

Permalink
Fix venv tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Nov 17, 2023
1 parent ece6a1c commit 384d422
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ jobs:
shell: pwsh
if: matrix.test-suite == 'venv'
run: |
# 1. For `terminalActivation.testvirtualenvs.test.ts`
# 1. For `*.testvirtualenvs.test.ts`
if ('${{ matrix.os }}' -match 'windows-latest') {
$condaPythonPath = Join-Path -Path $Env:CONDA -ChildPath python.exe
$condaExecPath = Join-Path -Path $Env:CONDA -ChildPath Scripts | Join-Path -ChildPath conda
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ jobs:
shell: pwsh
if: matrix.test-suite == 'venv'
run: |
# 1. For `terminalActivation.testvirtualenvs.test.ts`
# 1. For `*.testvirtualenvs.test.ts`
if ('${{ matrix.os }}' -match 'windows-latest') {
$condaPythonPath = Join-Path -Path $Env:CONDA -ChildPath python.exe
$condaExecPath = Join-Path -Path $Env:CONDA -ChildPath Scripts | Join-Path -ChildPath conda
Expand Down Expand Up @@ -451,7 +451,7 @@ jobs:
PYTHON_VIRTUAL_ENVS_LOCATION: './src/tmp/envPaths.json'
shell: pwsh
run: |
# 1. For `terminalActivation.testvirtualenvs.test.ts`
# 1. For `*.testvirtualenvs.test.ts`
if ('${{ matrix.os }}' -match 'windows-latest') {
$condaPythonPath = Join-Path -Path $Env:CONDA -ChildPath python.exe
$condaExecPath = Join-Path -Path $Env:CONDA -ChildPath Scripts | Join-Path -ChildPath conda
Expand Down
3 changes: 2 additions & 1 deletion src/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export namespace ThemeIcons {

export const DEFAULT_INTERPRETER_SETTING = 'python';

export const isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined;
export const isCI =
process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined || process.env.GITHUB_ACTIONS === 'true';

export function isTestExecution(): boolean {
return process.env.VSC_PYTHON_CI_TEST === '1' || isUnitTestExecution();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

Expand All @@ -10,11 +11,14 @@ import { CondaEnvironmentLocator } from '../../../../../client/pythonEnvironment
import { sleep } from '../../../../core';
import { createDeferred, Deferred } from '../../../../../client/common/utils/async';
import { PythonEnvsChangedEvent } from '../../../../../client/pythonEnvironments/base/watcher';
import { TEST_TIMEOUT } from '../../../../constants';
import { EXTENSION_ROOT_DIR_FOR_TESTS, TEST_TIMEOUT } from '../../../../constants';
import { traceWarn } from '../../../../../client/logging';
import { TEST_LAYOUT_ROOT } from '../../../common/commonTestConstants';
import { getEnvs } from '../../common';
import { assertBasicEnvsEqual } from '../envTestUtils';
import { PYTHON_VIRTUAL_ENVS_LOCATION } from '../../../../ciConstants';
import { isCI } from '../../../../../client/common/constants';
import * as externalDependencies from '../../../../../client/pythonEnvironments/common/externalDependencies';

class CondaEnvs {
private readonly condaEnvironmentsTxt;
Expand Down Expand Up @@ -55,6 +59,10 @@ class CondaEnvs {
suite('Conda Env Locator', async () => {
let locator: CondaEnvironmentLocator;
let condaEnvsTxt: CondaEnvs;
const envsLocation =
PYTHON_VIRTUAL_ENVS_LOCATION !== undefined
? path.join(EXTENSION_ROOT_DIR_FOR_TESTS, PYTHON_VIRTUAL_ENVS_LOCATION)
: path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'tmp', 'envPaths.json');

async function waitForChangeToBeDetected(deferred: Deferred<void>) {
const timeout = setTimeout(() => {
Expand All @@ -63,11 +71,23 @@ suite('Conda Env Locator', async () => {
}, TEST_TIMEOUT);
await deferred.promise;
}
let envPaths: any;

suiteSetup(async () => {
if (isCI) {
envPaths = await fs.readJson(envsLocation);
}
});

setup(async () => {
sinon.stub(platformUtils, 'getUserHomeDir').returns(TEST_LAYOUT_ROOT);
condaEnvsTxt = new CondaEnvs();
await condaEnvsTxt.cleanUp();
if (isCI) {
console.log('I am in CI');
console.log(JSON.stringify(envPaths));
sinon.stub(externalDependencies, 'getPythonSetting').returns(envPaths.condaExecPath);
}
});

async function setupLocator(onChanged: (e: PythonEnvsChangedEvent) => Promise<void>) {
Expand Down

0 comments on commit 384d422

Please sign in to comment.