diff --git a/.github/workflows/insiders.yml b/.github/workflows/insiders.yml index 9f3aa6fb94cc..3834931e8c68 100644 --- a/.github/workflows/insiders.yml +++ b/.github/workflows/insiders.yml @@ -174,6 +174,16 @@ jobs: python -m pip install pipenv python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath + - name: Prepare poetry for venv tests + env: + TEST_FILES_SUFFIX: testvirtualenvs + shell: pwsh + if: matrix.test-suite == 'venv' + run: | + python -m pip install poetry + Move-Item -Path ".\build\ci\pyproject.toml" -Destination . + poetry env use python + - name: Prepare virtualenv for venv tests env: TEST_FILES_SUFFIX: testvirtualenvs diff --git a/.github/workflows/nightly-coverage.yml b/.github/workflows/nightly-coverage.yml index 14ec3f310a1f..ad67d7870b0f 100644 --- a/.github/workflows/nightly-coverage.yml +++ b/.github/workflows/nightly-coverage.yml @@ -67,6 +67,16 @@ jobs: python -m pip install pipenv python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath + - name: Prepare poetry for venv tests + env: + TEST_FILES_SUFFIX: testvirtualenvs + shell: pwsh + if: matrix.test-suite == 'venv' + run: | + python -m pip install poetry + Move-Item -Path ".\build\ci\pyproject.toml" -Destination . + poetry env use python + - name: Prepare virtualenv for venv tests env: TEST_FILES_SUFFIX: testvirtualenvs diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index dff8e3e10c2c..0dfb9bd2a1e9 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -177,6 +177,16 @@ jobs: python -m pip install pipenv python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath + - name: Prepare poetry for venv tests + env: + TEST_FILES_SUFFIX: testvirtualenvs + shell: pwsh + if: matrix.test-suite == 'venv' + run: | + python -m pip install poetry + Move-Item -Path ".\build\ci\pyproject.toml" -Destination . + poetry env use python + - name: Prepare virtualenv for venv tests env: TEST_FILES_SUFFIX: testvirtualenvs @@ -485,6 +495,15 @@ jobs: python -m pip install pipenv python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath + - name: Prepare poetry for venv tests + env: + TEST_FILES_SUFFIX: testvirtualenvs + shell: pwsh + run: | + python -m pip install poetry + Move-Item -Path ".\build\ci\pyproject.toml" -Destination . + poetry env use python + - name: Prepare virtualenv for venv tests env: TEST_FILES_SUFFIX: testvirtualenvs diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index 4e270f1dab9c..93bf1b033b06 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -44,6 +44,7 @@ jobs: prereq-pattern: src/**/*.ts file-pattern: | src/**/*.test.ts + src/**/*.testvirtualenvs.ts .github/test_plan.md skip-label: 'skip tests' failure-message: 'TypeScript code was edited without also editing a ${file-pattern} file; see the Testing page in our wiki on testing guidelines (the ${skip-label} label can be used to pass this check)' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 02e00dbf0a7d..377d6539849c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -170,6 +170,16 @@ jobs: python -m pip install pipenv python -m pipenv run python ./build/ci/addEnvPath.py ${{env.PYTHON_VIRTUAL_ENVS_LOCATION}} pipenvPath + - name: Prepare poetry for venv tests + env: + TEST_FILES_SUFFIX: testvirtualenvs + shell: pwsh + if: matrix.test-suite == 'venv' + run: | + python -m pip install poetry + Move-Item -Path ".\build\ci\pyproject.toml" -Destination . + poetry env use python + - name: Prepare virtualenv for venv tests env: TEST_FILES_SUFFIX: testvirtualenvs diff --git a/build/ci/pyproject.toml b/build/ci/pyproject.toml new file mode 100644 index 000000000000..6335f021a637 --- /dev/null +++ b/build/ci/pyproject.toml @@ -0,0 +1,8 @@ +[tool.poetry] +name = "poetry-tutorial-project" +version = "0.1.0" +description = "" +authors = [""] + +[tool.poetry.dependencies] +python = "*" diff --git a/src/test/pythonEnvironments/discovery/locators/poetryLocator.testvirtualenvs.ts b/src/test/pythonEnvironments/discovery/locators/poetryLocator.testvirtualenvs.ts index b814a996fc76..6c80ffd14f58 100644 --- a/src/test/pythonEnvironments/discovery/locators/poetryLocator.testvirtualenvs.ts +++ b/src/test/pythonEnvironments/discovery/locators/poetryLocator.testvirtualenvs.ts @@ -1,16 +1,20 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +import { expect } from 'chai'; import * as path from 'path'; import * as sinon from 'sinon'; import { ExecutionResult, ShellOptions } from '../../../../client/common/process/types'; import { PythonEnvKind } from '../../../../client/pythonEnvironments/base/info'; +import { ILocator } from '../../../../client/pythonEnvironments/base/locator'; +import { getEnvs } from '../../../../client/pythonEnvironments/base/locatorUtils'; import * as externalDependencies from '../../../../client/pythonEnvironments/common/externalDependencies'; import { PoetryLocator } from '../../../../client/pythonEnvironments/discovery/locators/services/poetryLocator'; +import { EXTENSION_ROOT_DIR_FOR_TESTS } from '../../../constants'; import { TEST_LAYOUT_ROOT } from '../../common/commonTestConstants'; import { testLocatorWatcher } from './watcherTestUtils'; -suite('Poetry Locator', async () => { +suite('Poetry Watcher', async () => { let shellExecute: sinon.SinonStub; const testPoetryDir = path.join(TEST_LAYOUT_ROOT, 'poetry'); const project1 = path.join(testPoetryDir, 'project1'); @@ -38,3 +42,23 @@ suite('Poetry Locator', async () => { suiteTeardown(() => sinon.restore()); }); + +suite('Poetry Locator', async function () { + let locator: ILocator; + suiteSetup(async function () { + if (process.env.CI_PYTHON_VERSION && process.env.CI_PYTHON_VERSION.startsWith('2.')) { + // Poetry is soon to be deprecated for Python2.7, and tests do not pass + // as it is with pip installation of poetry, hence skip. + this.skip(); + } + locator = new PoetryLocator(EXTENSION_ROOT_DIR_FOR_TESTS); + }); + + test('Discovers existing poetry environments', async () => { + const items = await getEnvs(locator.iterEnvs()); + const isLocated = items.some( + (item) => item.kind === PythonEnvKind.Poetry && item.name.startsWith('poetry-tutorial-project'), + ); + expect(isLocated).to.equal(true); + }); +});