diff --git a/.config/CredScanSuppressions.json b/.config/CredScanSuppressions.json deleted file mode 100644 index cc237f71d86c..000000000000 --- a/.config/CredScanSuppressions.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "tool": "Credential Scanner", - "suppressions": [ - { - "file": [ - "file:///mnt/vss/_work/1/a/extension/extension/.nox/install_python_libs/lib/python3.8/site-packages/setuptools/_distutils/command%5Cregister.py", - "file:///mnt/vss/_work/1/b/extension/extension/.nox/install_python_libs/lib/python3.8/site-packages/setuptools/_distutils/command%5Cregister.py" - ], - "_justification": "These are not real passwords. For documentation purposes only." - } - ] - } diff --git a/.github/actions/build-vsix/action.yml b/.github/actions/build-vsix/action.yml index 929ecb31a6d3..c2515247de97 100644 --- a/.github/actions/build-vsix/action.yml +++ b/.github/actions/build-vsix/action.yml @@ -31,10 +31,10 @@ runs: uses: dtolnay/rust-toolchain@stable # Jedi LS depends on dataclasses which is not in the stdlib in Python 3.7. - - name: Use Python 3.8 for JediLSP + - name: Use Python 3.9 for JediLSP uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.9 cache: 'pip' cache-dependency-path: | requirements.txt diff --git a/.github/actions/smoke-tests/action.yml b/.github/actions/smoke-tests/action.yml index 2463f83ee90c..ed760e8b8202 100644 --- a/.github/actions/smoke-tests/action.yml +++ b/.github/actions/smoke-tests/action.yml @@ -13,13 +13,13 @@ runs: using: 'composite' steps: - name: Install Node - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ inputs.node_version }} cache: 'npm' - name: Install Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: '3.x' cache: 'pip' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 53ee0f003668..4b65b91a2cdf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -165,7 +165,7 @@ jobs: # macOS runners are expensive, and we assume that Ubuntu is enough to cover the Unix case. os: [ubuntu-latest, windows-latest] # Run the tests on the oldest and most recent versions of Python. - python: ['3.8', '3.x', '3.13-dev'] + python: ['3.9', '3.x', '3.13'] steps: - name: Checkout diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index b6bdaa8e250b..4b1ea54618b8 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -147,7 +147,7 @@ jobs: # macOS runners are expensive, and we assume that Ubuntu is enough to cover the Unix case. os: [ubuntu-latest, windows-latest] # Run the tests on the oldest and most recent versions of Python. - python: ['3.8', '3.x', '3.13-dev'] # run for 3 pytest versions, most recent stable, oldest version supported and pre-release + python: ['3.9', '3.x', '3.13'] # run for 3 pytest versions, most recent stable, oldest version supported and pre-release pytest-version: ['pytest', 'pytest@pre-release', 'pytest==6.2.0'] steps: diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index fcdf91b4f64b..b5ba2fe1f109 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -47,7 +47,8 @@ jobs: script: | const labels = context.payload.pull_request.labels.map(label => label.name); if (!labels.includes('skip-issue-check')) { - const issueLink = context.payload.pull_request.body.match(/https:\/\/github\.com\/\S+\/issues\/\d+/); + const prBody = context.payload.pull_request.body || ''; + const issueLink = prBody.match(/https:\/\/github\.com\/\S+\/issues\/\d+/); if (!issueLink) { core.setFailed('No associated issue found in the PR description.'); } diff --git a/build/azure-pipeline.pre-release.yml b/build/azure-pipeline.pre-release.yml index 3236b43d0098..6c6600365529 100644 --- a/build/azure-pipeline.pre-release.yml +++ b/build/azure-pipeline.pre-release.yml @@ -71,7 +71,7 @@ extends: - task: UsePythonVersion@0 inputs: - versionSpec: '3.8' + versionSpec: '3.9' addToPath: true architecture: 'x64' displayName: Select Python version diff --git a/build/azure-pipeline.stable.yml b/build/azure-pipeline.stable.yml index 2e7ebcfea82a..cae56854118e 100644 --- a/build/azure-pipeline.stable.yml +++ b/build/azure-pipeline.stable.yml @@ -65,7 +65,7 @@ extends: - task: UsePythonVersion@0 inputs: - versionSpec: '3.8' + versionSpec: '3.9' addToPath: true architecture: 'x64' displayName: Select Python version @@ -128,7 +128,7 @@ extends: project: 'Monaco' definition: 593 buildVersionToDownload: 'latestFromBranch' - branchName: 'refs/heads/release/2025.2' + branchName: 'refs/heads/release/2025.4' targetPath: '$(Build.SourcesDirectory)/python-env-tools/bin' artifactName: 'bin-$(buildTarget)' itemPattern: | diff --git a/build/ci/conda_env_1.yml b/build/ci/conda_env_1.yml index e9d08d0820a4..4f9ceefd27fb 100644 --- a/build/ci/conda_env_1.yml +++ b/build/ci/conda_env_1.yml @@ -1,4 +1,4 @@ name: conda_env_1 dependencies: - - python=3.8 + - python=3.9 - pip diff --git a/build/ci/conda_env_2.yml b/build/ci/conda_env_2.yml index 80b946c3cc14..af9d7a46ba3e 100644 --- a/build/ci/conda_env_2.yml +++ b/build/ci/conda_env_2.yml @@ -1,4 +1,4 @@ name: conda_env_2 dependencies: - - python=3.8 + - python=3.9 - pip diff --git a/build/test-requirements.txt b/build/test-requirements.txt index 8b0ea1636157..df9fd2b08c6e 100644 --- a/build/test-requirements.txt +++ b/build/test-requirements.txt @@ -28,10 +28,10 @@ namedpipe; platform_system == "Windows" # typing for Django files django-stubs -# for coverage coverage pytest-cov pytest-json +pytest-timeout # for pytest-describe related tests diff --git a/package-lock.json b/package-lock.json index 08905852f2ce..f04547ff9004 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "python", - "version": "2025.4.0", + "version": "2025.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "python", - "version": "2025.4.0", + "version": "2025.6.0", "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", @@ -13031,10 +13031,11 @@ } }, "node_modules/tar-fs": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", - "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.2.tgz", + "integrity": "sha512-EsaAXwxmx8UB7FRKqeozqEPop69DXcmYwTQwXvyAPF352HJsPdkVhvTaDPYqfNgruveJIJy3TA2l+2zj8LJIJA==", "dev": true, + "license": "MIT", "optional": true, "dependencies": { "chownr": "^1.1.1", @@ -24904,9 +24905,9 @@ "dev": true }, "tar-fs": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", - "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.2.tgz", + "integrity": "sha512-EsaAXwxmx8UB7FRKqeozqEPop69DXcmYwTQwXvyAPF352HJsPdkVhvTaDPYqfNgruveJIJy3TA2l+2zj8LJIJA==", "dev": true, "optional": true, "requires": { diff --git a/package.json b/package.json index 3fc7894a29bd..6e3a84107a1b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "python", "displayName": "Python", "description": "Python language support with extension access points for IntelliSense (Pylance), Debugging (Python Debugger), linting, formatting, refactoring, unit tests, and more.", - "version": "2025.4.0", + "version": "2025.6.0", "featureFlags": { "usingNewInterpreterStorage": true }, @@ -448,8 +448,7 @@ "pythonPromptNewToolsExt", "pythonTerminalEnvVarActivation", "pythonDiscoveryUsingWorkers", - "pythonTestAdapter", - "pythonREPLSmartSend" + "pythonTestAdapter" ], "enumDescriptions": [ "%python.experiments.All.description%", @@ -457,8 +456,7 @@ "%python.experiments.pythonPromptNewToolsExt.description%", "%python.experiments.pythonTerminalEnvVarActivation.description%", "%python.experiments.pythonDiscoveryUsingWorkers.description%", - "%python.experiments.pythonTestAdapter.description%", - "%python.experiments.pythonREPLSmartSend.description%" + "%python.experiments.pythonTestAdapter.description%" ] }, "scope": "window", @@ -475,8 +473,7 @@ "pythonPromptNewToolsExt", "pythonTerminalEnvVarActivation", "pythonDiscoveryUsingWorkers", - "pythonTestAdapter", - "pythonREPLSmartSend" + "pythonTestAdapter" ], "enumDescriptions": [ "%python.experiments.All.description%", @@ -484,8 +481,7 @@ "%python.experiments.pythonPromptNewToolsExt.description%", "%python.experiments.pythonTerminalEnvVarActivation.description%", "%python.experiments.pythonDiscoveryUsingWorkers.description%", - "%python.experiments.pythonTestAdapter.description%", - "%python.experiments.pythonREPLSmartSend.description%" + "%python.experiments.pythonTestAdapter.description%" ] }, "scope": "window", @@ -639,11 +635,7 @@ "default": false, "description": "%python.REPL.sendToNativeREPL.description%", "scope": "resource", - "type": "boolean", - "tags": [ - "onExP", - "preview" - ] + "type": "boolean" }, "python.REPL.provideVariables": { "default": true, diff --git a/package.nls.json b/package.nls.json index 8bff60a4b07d..2d4028063006 100644 --- a/package.nls.json +++ b/package.nls.json @@ -42,7 +42,6 @@ "python.experiments.pythonTerminalEnvVarActivation.description": "Enables use of environment variables to activate terminals instead of sending activation commands.", "python.experiments.pythonDiscoveryUsingWorkers.description": "Enables use of worker threads to do heavy computation when discovering interpreters.", "python.experiments.pythonTestAdapter.description": "Denotes the Python Test Adapter experiment.", - "python.experiments.pythonREPLSmartSend.description": "Denotes the Python REPL Smart Send experiment.", "python.experiments.pythonRecommendTensorboardExt.description": "Denotes the Tensorboard Extension recommendation experiment.", "python.globalModuleInstallation.description": "Whether to install Python modules globally when not using an environment.", "python.languageServer.description": "Defines type of the language server.", diff --git a/python_files/jedilsp_requirements/requirements.in b/python_files/jedilsp_requirements/requirements.in index 8bafda64375e..794e9c8ea686 100644 --- a/python_files/jedilsp_requirements/requirements.in +++ b/python_files/jedilsp_requirements/requirements.in @@ -1,8 +1,8 @@ # This file is used to generate requirements.txt. # To update requirements.txt, run the following commands. -# Use Python 3.8 when creating the environment or using pip-tools +# Use Python 3.9 when creating the environment or using pip-tools # 1) Install `uv` https://docs.astral.sh/uv/getting-started/installation/ -# 2) uv pip compile --generate-hashes --upgrade python_files\jedilsp_requirements\requirements.in > python_files\jedilsp_requirements\requirements.txt +# 2) uv pip compile --generate-hashes --upgrade python_files\jedilsp_requirements\requirements.in -o python_files\jedilsp_requirements\requirements.txt jedi-language-server>=0.34.3 pygls>=0.10.3 diff --git a/python_files/jedilsp_requirements/requirements.txt b/python_files/jedilsp_requirements/requirements.txt index ef4c7e1de6ae..0fc5cd76810f 100644 Binary files a/python_files/jedilsp_requirements/requirements.txt and b/python_files/jedilsp_requirements/requirements.txt differ diff --git a/python_files/tests/pytestadapter/helpers.py b/python_files/tests/pytestadapter/helpers.py index 7a75e6248844..4c337585bece 100644 --- a/python_files/tests/pytestadapter/helpers.py +++ b/python_files/tests/pytestadapter/helpers.py @@ -244,7 +244,7 @@ def runner_with_cwd_env( """ process_args: List[str] pipe_name: str - if "MANAGE_PY_PATH" in env_add: + if "MANAGE_PY_PATH" in env_add and "COVERAGE_ENABLED" not in env_add: # If we are running Django, generate a unittest-specific pipe name. process_args = [sys.executable, *args] pipe_name = generate_random_pipe_name("unittest-discovery-test") diff --git a/python_files/tests/pytestadapter/test_coverage.py b/python_files/tests/pytestadapter/test_coverage.py index d0f802a23672..d2d276172a8d 100644 --- a/python_files/tests/pytestadapter/test_coverage.py +++ b/python_files/tests/pytestadapter/test_coverage.py @@ -5,7 +5,9 @@ import pathlib import sys +import coverage import pytest +from packaging.version import Version script_dir = pathlib.Path(__file__).parent.parent sys.path.append(os.fspath(script_dir)) @@ -34,9 +36,9 @@ def test_simple_pytest_coverage(): cov_folder_path = TEST_DATA_PATH / "coverage_gen" actual = runner_with_cwd_env(args, cov_folder_path, env_add) assert actual - coverage = actual[-1] - assert coverage - results = coverage["result"] + cov = actual[-1] + assert cov + results = cov["result"] assert results assert len(results) == 3 focal_function_coverage = results.get(os.fspath(TEST_DATA_PATH / "coverage_gen" / "reverse.py")) @@ -46,6 +48,12 @@ def test_simple_pytest_coverage(): assert set(focal_function_coverage.get("lines_covered")) == {4, 5, 7, 9, 10, 11, 12, 13, 14, 17} assert len(set(focal_function_coverage.get("lines_missed"))) >= 3 + coverage_version = Version(coverage.__version__) + # only include check for branches if the version is >= 7.7.0 + if coverage_version >= Version("7.7.0"): + assert focal_function_coverage.get("executed_branches") == 4 + assert focal_function_coverage.get("total_branches") == 6 + coverage_gen_file_path = TEST_DATA_PATH / "coverage_gen" / "coverage.json" @@ -77,9 +85,9 @@ def test_coverage_gen_report(cleanup_coverage_gen_file): # noqa: ARG001 print("cov_folder_path", cov_folder_path) actual = runner_with_cwd_env(args, cov_folder_path, env_add) assert actual - coverage = actual[-1] - assert coverage - results = coverage["result"] + cov = actual[-1] + assert cov + results = cov["result"] assert results assert len(results) == 3 focal_function_coverage = results.get(os.fspath(TEST_DATA_PATH / "coverage_gen" / "reverse.py")) @@ -88,6 +96,11 @@ def test_coverage_gen_report(cleanup_coverage_gen_file): # noqa: ARG001 assert focal_function_coverage.get("lines_missed") is not None assert set(focal_function_coverage.get("lines_covered")) == {4, 5, 7, 9, 10, 11, 12, 13, 14, 17} assert set(focal_function_coverage.get("lines_missed")) == {18, 19, 6} + coverage_version = Version(coverage.__version__) + # only include check for branches if the version is >= 7.7.0 + if coverage_version >= Version("7.7.0"): + assert focal_function_coverage.get("executed_branches") == 4 + assert focal_function_coverage.get("total_branches") == 6 # assert that the coverage file was created at the right path assert os.path.exists(coverage_gen_file_path) # noqa: PTH110 @@ -123,9 +136,9 @@ def test_coverage_w_omit_config(): actual = runner_with_cwd_env([], cov_folder_path, env_add) assert actual print("actual", json.dumps(actual, indent=2)) - coverage = actual[-1] - assert coverage - results = coverage["result"] + cov = actual[-1] + assert cov + results = cov["result"] assert results # assert one file is reported and one file (as specified in pyproject.toml) is omitted assert len(results) == 1 diff --git a/python_files/tests/unittestadapter/.data/simple_django/old_manage.py b/python_files/tests/unittestadapter/.data/simple_django/old_manage.py new file mode 100755 index 000000000000..844b98b4edba --- /dev/null +++ b/python_files/tests/unittestadapter/.data/simple_django/old_manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +import os +import sys +if __name__ == "__main__": + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/python_files/tests/unittestadapter/test_coverage.py b/python_files/tests/unittestadapter/test_coverage.py index 594aa764370e..76fdfec43376 100644 --- a/python_files/tests/unittestadapter/test_coverage.py +++ b/python_files/tests/unittestadapter/test_coverage.py @@ -8,6 +8,10 @@ import pathlib import sys +import coverage +import pytest +from packaging.version import Version + sys.path.append(os.fspath(pathlib.Path(__file__).parent)) python_files_path = pathlib.Path(__file__).parent.parent.parent @@ -38,9 +42,9 @@ def test_basic_coverage(): ) assert actual - coverage = actual[-1] - assert coverage - results = coverage["result"] + cov = actual[-1] + assert cov + results = cov["result"] assert results assert len(results) == 3 focal_function_coverage = results.get(os.fspath(TEST_DATA_PATH / "coverage_ex" / "reverse.py")) @@ -49,3 +53,54 @@ def test_basic_coverage(): assert focal_function_coverage.get("lines_missed") is not None assert set(focal_function_coverage.get("lines_covered")) == {4, 5, 7, 9, 10, 11, 12, 13, 14} assert set(focal_function_coverage.get("lines_missed")) == {6} + coverage_version = Version(coverage.__version__) + # only include check for branches if the version is >= 7.7.0 + if coverage_version >= Version("7.7.0"): + assert focal_function_coverage.get("executed_branches") == 3 + assert focal_function_coverage.get("total_branches") == 4 + + +@pytest.mark.parametrize("manage_py_file", ["manage.py", "old_manage.py"]) +@pytest.mark.timeout(30) +def test_basic_django_coverage(manage_py_file): + """This test validates that the coverage is correctly calculated for a Django project.""" + data_path: pathlib.Path = TEST_DATA_PATH / "simple_django" + manage_py_path: str = os.fsdecode(data_path / manage_py_file) + execution_script: pathlib.Path = python_files_path / "unittestadapter" / "execution.py" + + test_ids = [ + "polls.tests.QuestionModelTests.test_was_published_recently_with_future_question", + "polls.tests.QuestionModelTests.test_was_published_recently_with_future_question_2", + "polls.tests.QuestionModelTests.test_question_creation_and_retrieval", + ] + + script_str = os.fsdecode(execution_script) + actual = helpers.runner_with_cwd_env( + [script_str, "--udiscovery", "-p", "*test*.py", *test_ids], + data_path, + { + "MANAGE_PY_PATH": manage_py_path, + "_TEST_VAR_UNITTEST": "True", + "COVERAGE_ENABLED": os.fspath(data_path), + }, + ) + + assert actual + cov = actual[-1] + assert cov + results = cov["result"] + assert results + assert len(results) == 16 + polls_views_coverage = results.get(str(data_path / "polls" / "views.py")) + assert polls_views_coverage + assert polls_views_coverage.get("lines_covered") is not None + assert polls_views_coverage.get("lines_missed") is not None + assert set(polls_views_coverage.get("lines_covered")) == {3, 4, 6} + assert set(polls_views_coverage.get("lines_missed")) == {7} + + model_cov = results.get(str(data_path / "polls" / "models.py")) + coverage_version = Version(coverage.__version__) + # only include check for branches if the version is >= 7.7.0 + if coverage_version >= Version("7.7.0"): + assert model_cov.get("executed_branches") == 1 + assert model_cov.get("total_branches") == 2 diff --git a/python_files/unittestadapter/django_handler.py b/python_files/unittestadapter/django_handler.py index 9daa816d0918..77c50efc27d0 100644 --- a/python_files/unittestadapter/django_handler.py +++ b/python_files/unittestadapter/django_handler.py @@ -5,7 +5,8 @@ import pathlib import subprocess import sys -from typing import List +from contextlib import contextmanager, suppress +from typing import Generator, List script_dir = pathlib.Path(__file__).parent sys.path.append(os.fspath(script_dir)) @@ -16,6 +17,17 @@ ) +@contextmanager +def override_argv(argv: List[str]) -> Generator: + """Context manager to temporarily override sys.argv with the provided arguments.""" + original_argv = sys.argv + sys.argv = argv + try: + yield + finally: + sys.argv = original_argv + + def django_discovery_runner(manage_py_path: str, args: List[str]) -> None: # Attempt a small amount of validation on the manage.py path. if not pathlib.Path(manage_py_path).exists(): @@ -58,8 +70,9 @@ def django_discovery_runner(manage_py_path: str, args: List[str]) -> None: def django_execution_runner(manage_py_path: str, test_ids: List[str], args: List[str]) -> None: + manage_path: pathlib.Path = pathlib.Path(manage_py_path) # Attempt a small amount of validation on the manage.py path. - if not pathlib.Path(manage_py_path).exists(): + if not manage_path.exists(): raise VSCodeUnittestError("Error running Django, manage.py path does not exist.") try: @@ -72,31 +85,27 @@ def django_execution_runner(manage_py_path: str, test_ids: List[str], args: List else: env["PYTHONPATH"] = os.fspath(custom_test_runner_dir) - # Build command to run 'python manage.py test'. - command: List[str] = [ - sys.executable, - manage_py_path, + django_project_dir: pathlib.Path = manage_path.parent + sys.path.insert(0, os.fspath(django_project_dir)) + print(f"Django project directory: {django_project_dir}") + + manage_argv: List[str] = [ + str(manage_path), "test", "--testrunner=django_test_runner.CustomExecutionTestRunner", + *args, + *test_ids, ] - # Add any additional arguments to the command provided by the user. - command.extend(args) - # Add the test_ids to the command. - print("Test IDs: ", test_ids) - print("args: ", args) - command.extend(test_ids) - print("Running Django run tests with command: ", command) - subprocess_execution = subprocess.run( - command, - capture_output=True, - text=True, - env=env, - ) - print(subprocess_execution.stderr, file=sys.stderr) - print(subprocess_execution.stdout, file=sys.stdout) - # Zero return code indicates success, 1 indicates test failures, so both are considered successful. - if subprocess_execution.returncode not in (0, 1): - error_msg = "Django test execution process exited with non-zero error code See stderr above for more details." - print(error_msg, file=sys.stderr) + print(f"Django manage.py arguments: {manage_argv}") + + try: + argv_context = override_argv(manage_argv) + suppress_context = suppress(SystemExit) + manage_file = manage_path.open() + with argv_context, suppress_context, manage_file: + manage_code = manage_file.read() + exec(manage_code, {"__name__": "__main__"}) + except OSError as e: + raise VSCodeUnittestError("Error running Django, unable to read manage.py") from e except Exception as e: print(f"Error during Django test execution: {e}", file=sys.stderr) diff --git a/python_files/unittestadapter/execution.py b/python_files/unittestadapter/execution.py index 644b233fc530..8df2f279aa71 100644 --- a/python_files/unittestadapter/execution.py +++ b/python_files/unittestadapter/execution.py @@ -12,6 +12,8 @@ from types import TracebackType from typing import Dict, List, Optional, Set, Tuple, Type, Union +from packaging.version import Version + # Adds the scripts directory to the PATH as a workaround for enabling shell for test execution. path_var_name = "PATH" if "PATH" in os.environ else "Path" os.environ[path_var_name] = ( @@ -316,6 +318,7 @@ def send_run_data(raw_data, test_run_pipe): # For unittest COVERAGE_ENABLED is to the root of the workspace so correct data is collected cov = None is_coverage_run = os.environ.get("COVERAGE_ENABLED") is not None + include_branches = False if is_coverage_run: print( "COVERAGE_ENABLED env var set, starting coverage. workspace_root used as parent dir:", @@ -323,6 +326,11 @@ def send_run_data(raw_data, test_run_pipe): ) import coverage + coverage_version = Version(coverage.__version__) + # only include branches if coverage version is 7.7.0 or greater (as this was when the api saves) + if coverage_version >= Version("7.7.0"): + include_branches = True + source_ar: List[str] = [] if workspace_root: source_ar.append(workspace_root) @@ -330,7 +338,9 @@ def send_run_data(raw_data, test_run_pipe): source_ar.append(top_level_dir) if start_dir: source_ar.append(os.path.abspath(start_dir)) # noqa: PTH100 - cov = coverage.Coverage(branch=True, source=source_ar) # is at least 1 of these required?? + cov = coverage.Coverage( + branch=include_branches, source=source_ar + ) # is at least 1 of these required?? cov.start() # If no error occurred, we will have test ids to run. @@ -362,12 +372,22 @@ def send_run_data(raw_data, test_run_pipe): file_coverage_map: Dict[str, FileCoverageInfo] = {} for file in file_set: analysis = cov.analysis2(file) + taken_file_branches = 0 + total_file_branches = -1 + + if include_branches: + branch_stats: dict[int, tuple[int, int]] = cov.branch_stats(file) + total_file_branches = sum([total_exits for total_exits, _ in branch_stats.values()]) + taken_file_branches = sum([taken_exits for _, taken_exits in branch_stats.values()]) + lines_executable = {int(line_no) for line_no in analysis[1]} lines_missed = {int(line_no) for line_no in analysis[3]} lines_covered = lines_executable - lines_missed file_info: FileCoverageInfo = { "lines_covered": list(lines_covered), # list of int "lines_missed": list(lines_missed), # list of int + "executed_branches": taken_file_branches, + "total_branches": total_file_branches, } file_coverage_map[file] = file_info diff --git a/python_files/unittestadapter/pvsc_utils.py b/python_files/unittestadapter/pvsc_utils.py index 4d1cbfb5e110..017bad38966a 100644 --- a/python_files/unittestadapter/pvsc_utils.py +++ b/python_files/unittestadapter/pvsc_utils.py @@ -75,6 +75,8 @@ class ExecutionPayloadDict(TypedDict): class FileCoverageInfo(TypedDict): lines_covered: List[int] lines_missed: List[int] + executed_branches: int + total_branches: int class CoveragePayloadDict(Dict): diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 00f356e20dcd..649e5bc59058 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -13,6 +13,7 @@ from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, TypedDict import pytest +from packaging.version import Version if TYPE_CHECKING: from pluggy import Result @@ -61,6 +62,7 @@ def __init__(self, message): collected_tests_so_far = [] TEST_RUN_PIPE = os.getenv("TEST_RUN_PIPE") SYMLINK_PATH = None +INCLUDE_BRANCHES = False def pytest_load_initial_conftests(early_config, parser, args): # noqa: ARG001 @@ -70,6 +72,9 @@ def pytest_load_initial_conftests(early_config, parser, args): # noqa: ARG001 raise VSCodePytestError( "\n \nERROR: pytest-cov is not installed, please install this before running pytest with coverage as pytest-cov is required. \n" ) + if "--cov-branch" in args: + global INCLUDE_BRANCHES + INCLUDE_BRANCHES = True global TEST_RUN_PIPE TEST_RUN_PIPE = os.getenv("TEST_RUN_PIPE") @@ -121,7 +126,7 @@ def pytest_internalerror(excrepr, excinfo): # noqa: ARG001 excinfo -- the exception information of type ExceptionInfo. """ # call.excinfo.exconly() returns the exception as a string. - ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.") + ERRORS.append(excinfo.exconly() + "\n Check Python Logs for more details.") def pytest_exception_interact(node, call, report): @@ -139,9 +144,9 @@ def pytest_exception_interact(node, call, report): if call.excinfo and call.excinfo.typename != "AssertionError": if report.outcome == "skipped" and "SkipTest" in str(call): return - ERRORS.append(call.excinfo.exconly() + "\n Check Python Test Logs for more details.") + ERRORS.append(call.excinfo.exconly() + "\n Check Python Logs for more details.") else: - ERRORS.append(report.longreprtext + "\n Check Python Test Logs for more details.") + ERRORS.append(report.longreprtext + "\n Check Python Logs for more details.") else: # If during execution, send this data that the given node failed. report_value = "error" @@ -204,7 +209,7 @@ def pytest_keyboard_interrupt(excinfo): excinfo -- the exception information of type ExceptionInfo. """ # The function execonly() returns the exception as a string. - ERRORS.append(excinfo.exconly() + "\n Check Python Test Logs for more details.") + ERRORS.append(excinfo.exconly() + "\n Check Python Logs for more details.") class TestOutcome(Dict): @@ -363,6 +368,8 @@ def check_skipped_condition(item): class FileCoverageInfo(TypedDict): lines_covered: list[int] lines_missed: list[int] + executed_branches: int + total_branches: int def pytest_sessionfinish(session, exitstatus): @@ -436,6 +443,15 @@ def pytest_sessionfinish(session, exitstatus): # load the report and build the json result to return import coverage + coverage_version = Version(coverage.__version__) + global INCLUDE_BRANCHES + # only include branches if coverage version is 7.7.0 or greater (as this was when the api saves) + if coverage_version < Version("7.7.0") and INCLUDE_BRANCHES: + print( + "Plugin warning[vscode-pytest]: Branch coverage not supported in this coverage versions < 7.7.0. Please upgrade coverage package if you would like to see branch coverage." + ) + INCLUDE_BRANCHES = False + try: from coverage.exceptions import NoSource except ImportError: @@ -448,9 +464,8 @@ def pytest_sessionfinish(session, exitstatus): file_coverage_map: dict[str, FileCoverageInfo] = {} # remove files omitted per coverage report config if any - omit_files = cov.config.report_omit - if omit_files: - print("Plugin info[vscode-pytest]: Omit files/rules: ", omit_files) + omit_files: list[str] | None = cov.config.report_omit + if omit_files is not None: for pattern in omit_files: for file in list(file_set): if pathlib.Path(file).match(pattern): @@ -459,6 +474,18 @@ def pytest_sessionfinish(session, exitstatus): for file in file_set: try: analysis = cov.analysis2(file) + taken_file_branches = 0 + total_file_branches = -1 + + if INCLUDE_BRANCHES: + branch_stats: dict[int, tuple[int, int]] = cov.branch_stats(file) + total_file_branches = sum( + [total_exits for total_exits, _ in branch_stats.values()] + ) + taken_file_branches = sum( + [taken_exits for _, taken_exits in branch_stats.values()] + ) + except NoSource: # as per issue 24308 this best way to handle this edge case continue @@ -473,7 +500,12 @@ def pytest_sessionfinish(session, exitstatus): file_info: FileCoverageInfo = { "lines_covered": list(lines_covered), # list of int "lines_missed": list(lines_missed), # list of int + "executed_branches": taken_file_branches, + "total_branches": total_file_branches, } + # convert relative path to absolute path + if not pathlib.Path(file).is_absolute(): + file = str(pathlib.Path(file).resolve()) file_coverage_map[file] = file_info payload: CoveragePayloadDict = CoveragePayloadDict( diff --git a/python_files/vscode_pytest/run_pytest_script.py b/python_files/vscode_pytest/run_pytest_script.py index 1abfb8b27004..c0f5114b375c 100644 --- a/python_files/vscode_pytest/run_pytest_script.py +++ b/python_files/vscode_pytest/run_pytest_script.py @@ -47,7 +47,7 @@ def run_pytest(args): coverage_enabled = True break if not coverage_enabled: - args = [*args, "--cov=."] + args = [*args, "--cov=.", "--cov-branch"] run_test_ids_pipe = os.environ.get("RUN_TEST_IDS_PIPE") if run_test_ids_pipe: diff --git a/requirements.in b/requirements.in index d0e553cb9a5b..a1e2243c553e 100644 --- a/requirements.in +++ b/requirements.in @@ -1,10 +1,10 @@ # This file is used to generate requirements.txt. # To update requirements.txt, run the following commands. # 1) Install `uv` https://docs.astral.sh/uv/getting-started/installation/ -# 2) uv pip compile --generate-hashes --upgrade requirements.in > requirements.txt +# 2) uv pip compile --generate-hashes --upgrade requirements.in -o requirements.txt # Unittest test adapter -typing-extensions==4.12.2 +typing-extensions==4.13.2 # Fallback env creator for debian microvenv diff --git a/requirements.txt b/requirements.txt index 464d3abb1315..3983d5414c54 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/client/activation/jedi/analysisOptions.ts b/src/client/activation/jedi/analysisOptions.ts index 3b1897b91088..007008dc9b13 100644 --- a/src/client/activation/jedi/analysisOptions.ts +++ b/src/client/activation/jedi/analysisOptions.ts @@ -85,6 +85,9 @@ export class JediLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt maxSymbols: 0, }, }, + semantic_tokens: { + enable: true, + }, }; } } diff --git a/src/client/common/application/commands.ts b/src/client/common/application/commands.ts index 2195fe09aabf..98ea2669d773 100644 --- a/src/client/common/application/commands.ts +++ b/src/client/common/application/commands.ts @@ -107,4 +107,5 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu }, ]; ['cursorEnd']: []; + ['python-envs.createTerminal']: [undefined | Uri]; } diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index 7ae3467b2cfd..634e0106fe7b 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -21,11 +21,12 @@ import { sendSettingTelemetry } from '../telemetry/envFileTelemetry'; import { ITestingSettings } from '../testing/configuration/types'; import { IWorkspaceService } from './application/types'; import { WorkspaceService } from './application/workspace'; -import { DEFAULT_INTERPRETER_SETTING, isTestExecution } from './constants'; +import { DEFAULT_INTERPRETER_SETTING, isTestExecution, PYREFLY_EXTENSION_ID } from './constants'; import { IAutoCompleteSettings, IDefaultLanguageServer, IExperiments, + IExtensions, IInterpreterPathService, IInterpreterSettings, IPythonSettings, @@ -140,6 +141,7 @@ export class PythonSettings implements IPythonSettings { workspace: IWorkspaceService, private readonly interpreterPathService: IInterpreterPathService, private readonly defaultLS: IDefaultLanguageServer | undefined, + private readonly extensions: IExtensions, ) { this.workspace = workspace || new WorkspaceService(); this.workspaceRoot = workspaceFolder; @@ -152,6 +154,7 @@ export class PythonSettings implements IPythonSettings { workspace: IWorkspaceService, interpreterPathService: IInterpreterPathService, defaultLS: IDefaultLanguageServer | undefined, + extensions: IExtensions, ): PythonSettings { workspace = workspace || new WorkspaceService(); const workspaceFolderUri = PythonSettings.getSettingsUriAndTarget(resource, workspace).uri; @@ -164,6 +167,7 @@ export class PythonSettings implements IPythonSettings { workspace, interpreterPathService, defaultLS, + extensions, ); PythonSettings.pythonSettings.set(workspaceFolderKey, settings); settings.onDidChange((event) => PythonSettings.debounceConfigChangeNotification(event)); @@ -275,7 +279,14 @@ export class PythonSettings implements IPythonSettings { userLS === 'Microsoft' || !Object.values(LanguageServerType).includes(userLS as LanguageServerType) ) { - this.languageServer = this.defaultLS?.defaultLSType ?? LanguageServerType.None; + if ( + this.extensions.getExtension(PYREFLY_EXTENSION_ID) && + pythonSettings.get('pyrefly.disableLanguageServices') !== true + ) { + this.languageServer = LanguageServerType.None; + } else { + this.languageServer = this.defaultLS?.defaultLSType ?? LanguageServerType.None; + } this.languageServerIsDefault = true; } else if (userLS === 'JediLSP') { // Switch JediLSP option to Jedi. diff --git a/src/client/common/configuration/service.ts b/src/client/common/configuration/service.ts index 219c8727ca16..443990b2e5da 100644 --- a/src/client/common/configuration/service.ts +++ b/src/client/common/configuration/service.ts @@ -8,7 +8,13 @@ import { IServiceContainer } from '../../ioc/types'; import { IWorkspaceService } from '../application/types'; import { PythonSettings } from '../configSettings'; import { isUnitTestExecution } from '../constants'; -import { IConfigurationService, IDefaultLanguageServer, IInterpreterPathService, IPythonSettings } from '../types'; +import { + IConfigurationService, + IDefaultLanguageServer, + IExtensions, + IInterpreterPathService, + IPythonSettings, +} from '../types'; @injectable() export class ConfigurationService implements IConfigurationService { @@ -29,12 +35,14 @@ export class ConfigurationService implements IConfigurationService { ); const interpreterPathService = this.serviceContainer.get(IInterpreterPathService); const defaultLS = this.serviceContainer.tryGet(IDefaultLanguageServer); + const extensions = this.serviceContainer.get(IExtensions); return PythonSettings.getInstance( resource, InterpreterAutoSelectionService, this.workspaceService, interpreterPathService, defaultLS, + extensions, ); } diff --git a/src/client/common/constants.ts b/src/client/common/constants.ts index 5ffa775bf04a..4a8962e86b58 100644 --- a/src/client/common/constants.ts +++ b/src/client/common/constants.ts @@ -22,6 +22,7 @@ export const PYTHON_NOTEBOOKS = [ export const PVSC_EXTENSION_ID = 'ms-python.python'; export const PYLANCE_EXTENSION_ID = 'ms-python.vscode-pylance'; +export const PYREFLY_EXTENSION_ID = 'meta.pyrefly'; export const JUPYTER_EXTENSION_ID = 'ms-toolsai.jupyter'; export const TENSORBOARD_EXTENSION_ID = 'ms-toolsai.tensorboard'; export const AppinsightsKey = '0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255'; diff --git a/src/client/common/types.ts b/src/client/common/types.ts index cec297f8329a..2cb393d89bdf 100644 --- a/src/client/common/types.ts +++ b/src/client/common/types.ts @@ -16,7 +16,6 @@ import { Memento, LogOutputChannel, Uri, - OutputChannel, } from 'vscode'; import { LanguageServerType } from '../activation/types'; import type { InstallOptions, InterpreterUri, ModuleInstallFlags } from './installer/types'; @@ -29,8 +28,6 @@ export interface IDisposable { export const ILogOutputChannel = Symbol('ILogOutputChannel'); export interface ILogOutputChannel extends LogOutputChannel {} -export const ITestOutputChannel = Symbol('ITestOutputChannel'); -export interface ITestOutputChannel extends OutputChannel {} export const IDocumentSymbolProvider = Symbol('IDocumentSymbolProvider'); export interface IDocumentSymbolProvider extends DocumentSymbolProvider {} export const IsWindows = Symbol('IS_WINDOWS'); diff --git a/src/client/common/utils/localize.ts b/src/client/common/utils/localize.ts index 18ab501f241b..97fe6201e4fb 100644 --- a/src/client/common/utils/localize.ts +++ b/src/client/common/utils/localize.ts @@ -257,7 +257,6 @@ export namespace InterpreterQuickPickList { export namespace OutputChannelNames { export const languageServer = l10n.t('Python Language Server'); export const python = l10n.t('Python'); - export const pythonTest = l10n.t('Python Test Log'); } export namespace Linters { diff --git a/src/client/common/vscodeApis/commandApis.ts b/src/client/common/vscodeApis/commandApis.ts index 580760e106e1..908cb761c538 100644 --- a/src/client/common/vscodeApis/commandApis.ts +++ b/src/client/common/vscodeApis/commandApis.ts @@ -3,13 +3,16 @@ import { commands, Disposable } from 'vscode'; -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/** + * Wrapper for vscode.commands.executeCommand to make it easier to mock in tests + */ +export function executeCommand(command: string, ...rest: any[]): Thenable { + return commands.executeCommand(command, ...rest); +} +/** + * Wrapper for vscode.commands.registerCommand to make it easier to mock in tests + */ export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { return commands.registerCommand(command, callback, thisArg); } - -export function executeCommand(command: string, ...rest: any[]): Thenable { - return commands.executeCommand(command, ...rest); -} diff --git a/src/client/common/vscodeApis/windowApis.ts b/src/client/common/vscodeApis/windowApis.ts index fc63a189f2ff..fade0a028487 100644 --- a/src/client/common/vscodeApis/windowApis.ts +++ b/src/client/common/vscodeApis/windowApis.ts @@ -22,6 +22,9 @@ import { LogOutputChannel, OutputChannel, TerminalLinkProvider, + NotebookDocument, + NotebookEditor, + NotebookDocumentShowOptions, } from 'vscode'; import { createDeferred, Deferred } from '../utils/async'; import { Resource } from '../types'; @@ -31,6 +34,13 @@ export function showTextDocument(uri: Uri): Thenable { return window.showTextDocument(uri); } +export function showNotebookDocument( + document: NotebookDocument, + options?: NotebookDocumentShowOptions, +): Thenable { + return window.showNotebookDocument(document, options); +} + export function showQuickPick( items: readonly T[] | Thenable, options?: QuickPickOptions, diff --git a/src/client/common/vscodeApis/workspaceApis.ts b/src/client/common/vscodeApis/workspaceApis.ts index cb516da73075..cd45f655702d 100644 --- a/src/client/common/vscodeApis/workspaceApis.ts +++ b/src/client/common/vscodeApis/workspaceApis.ts @@ -60,6 +60,10 @@ export function onDidChangeConfiguration(handler: (e: vscode.ConfigurationChange return vscode.workspace.onDidChangeConfiguration(handler); } +export function onDidCloseNotebookDocument(handler: (e: vscode.NotebookDocument) => void): vscode.Disposable { + return vscode.workspace.onDidCloseNotebookDocument(handler); +} + export function createFileSystemWatcher( globPattern: vscode.GlobPattern, ignoreCreateEvents?: boolean, @@ -98,6 +102,15 @@ export function createDirectory(uri: vscode.Uri): Thenable { return vscode.workspace.fs.createDirectory(uri); } +export function openNotebookDocument(uri: vscode.Uri): Thenable; +export function openNotebookDocument( + notebookType: string, + content?: vscode.NotebookData, +): Thenable; +export function openNotebookDocument(notebook: any, content?: vscode.NotebookData): Thenable { + return vscode.workspace.openNotebookDocument(notebook, content); +} + export function copy(source: vscode.Uri, dest: vscode.Uri, options?: { overwrite?: boolean }): Thenable { return vscode.workspace.fs.copy(source, dest, options); } diff --git a/src/client/envExt/api.legacy.ts b/src/client/envExt/api.legacy.ts index 7546a429c76a..fb01e73bdfcf 100644 --- a/src/client/envExt/api.legacy.ts +++ b/src/client/envExt/api.legacy.ts @@ -1,14 +1,14 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -import { Terminal, Uri, WorkspaceFolder } from 'vscode'; +import { Terminal, Uri } from 'vscode'; import { getEnvExtApi, getEnvironment } from './api.internal'; import { EnvironmentType, PythonEnvironment as PythonEnvironmentLegacy } from '../pythonEnvironments/info'; import { PythonEnvironment, PythonTerminalOptions } from './types'; import { Architecture } from '../common/utils/platform'; import { parseVersion } from '../pythonEnvironments/base/info/pythonVersion'; import { PythonEnvType } from '../pythonEnvironments/base/info'; -import { traceError, traceInfo } from '../logging'; +import { traceError } from '../logging'; import { reportActiveInterpreterChanged } from '../environmentApi'; import { getWorkspaceFolder, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis'; @@ -120,36 +120,6 @@ export async function getActiveInterpreterLegacy(resource?: Uri): Promise void, -): Promise { - const api = await getEnvExtApi(); - const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath)); - if (!pythonEnv) { - traceError(`EnvExt: Failed to resolve environment for ${pythonPath}`); - return; - } - - const envType = toEnvironmentType(pythonEnv); - if (envType === EnvironmentType.Conda) { - const packages = await api.getPackages(pythonEnv); - if (packages && packages.length > 0 && packages.some((pkg) => pkg.name.toLowerCase() === 'python')) { - return; - } - traceInfo(`EnvExt: Python not found in ${envType} environment ${pythonPath}`); - traceInfo(`EnvExt: Installing Python in ${envType} environment ${pythonPath}`); - await api.installPackages(pythonEnv, ['python']); - previousEnvMap.set(workspaceFolder?.uri.fsPath || '', pythonEnv); - reportActiveInterpreterChanged({ - path: pythonPath, - resource: workspaceFolder, - }); - callback(); - } -} - export async function setInterpreterLegacy(pythonPath: string, uri: Uri | undefined): Promise { const api = await getEnvExtApi(); const pythonEnv = await api.resolveEnvironment(Uri.file(pythonPath)); diff --git a/src/client/extensionInit.ts b/src/client/extensionInit.ts index 1332dc6bd070..b161643d2d97 100644 --- a/src/client/extensionInit.ts +++ b/src/client/extensionInit.ts @@ -4,7 +4,7 @@ 'use strict'; import { Container } from 'inversify'; -import { Disposable, l10n, Memento, window } from 'vscode'; +import { Disposable, Memento, window } from 'vscode'; import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry'; import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry'; import { registerTypes as commonRegisterTypes } from './common/serviceRegistry'; @@ -15,7 +15,6 @@ import { IExtensionContext, IMemento, ILogOutputChannel, - ITestOutputChannel, WORKSPACE_MEMENTO, } from './common/types'; import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry'; @@ -28,7 +27,6 @@ import * as pythonEnvironments from './pythonEnvironments'; import { IDiscoveryAPI } from './pythonEnvironments/base/locator'; import { registerLogger } from './logging'; import { OutputChannelLogger } from './logging/outputChannelLogger'; -import { isTrusted, isVirtualWorkspace } from './common/vscodeApis/workspaceApis'; // The code in this module should do nothing more complex than register // objects to DI and simple init (e.g. no side effects). That implies @@ -56,14 +54,7 @@ export function initializeGlobals( disposables.push(standardOutputChannel); disposables.push(registerLogger(new OutputChannelLogger(standardOutputChannel))); - const unitTestOutChannel = window.createOutputChannel(OutputChannelNames.pythonTest); - disposables.push(unitTestOutChannel); - if (isVirtualWorkspace() || !isTrusted()) { - unitTestOutChannel.appendLine(l10n.t('Unit tests are not supported in this environment.')); - } - serviceManager.addSingletonInstance(ILogOutputChannel, standardOutputChannel); - serviceManager.addSingletonInstance(ITestOutputChannel, unitTestOutChannel); return { context, diff --git a/src/client/interpreter/interpreterService.ts b/src/client/interpreter/interpreterService.ts index 3a1aaed312ff..ad06fd7d051d 100644 --- a/src/client/interpreter/interpreterService.ts +++ b/src/client/interpreter/interpreterService.ts @@ -45,7 +45,7 @@ import { } from '../pythonEnvironments/base/locator'; import { sleep } from '../common/utils/async'; import { useEnvExtension } from '../envExt/api.internal'; -import { ensureEnvironmentContainsPythonLegacy, getActiveInterpreterLegacy } from '../envExt/api.legacy'; +import { getActiveInterpreterLegacy } from '../envExt/api.legacy'; type StoredPythonEnvironment = PythonEnvironment & { store?: boolean }; @@ -290,9 +290,6 @@ export class InterpreterService implements Disposable, IInterpreterService { @cache(-1, true) private async ensureEnvironmentContainsPython(pythonPath: string, workspaceFolder: WorkspaceFolder | undefined) { if (useEnvExtension()) { - await ensureEnvironmentContainsPythonLegacy(pythonPath, workspaceFolder, () => { - this.didChangeInterpreterEmitter.fire(workspaceFolder?.uri); - }); return; } diff --git a/src/client/providers/terminalProvider.ts b/src/client/providers/terminalProvider.ts index 407a5520b29a..841f479269ac 100644 --- a/src/client/providers/terminalProvider.ts +++ b/src/client/providers/terminalProvider.ts @@ -60,8 +60,13 @@ export class TerminalProvider implements Disposable { @captureTelemetry(EventName.TERMINAL_CREATE, { triggeredBy: 'commandpalette' }) private async onCreateTerminal() { - const terminalService = this.serviceContainer.get(ITerminalServiceFactory); const activeResource = this.activeResourceService.getActiveResource(); + if (useEnvExtension()) { + const commandManager = this.serviceContainer.get(ICommandManager); + await commandManager.executeCommand('python-envs.createTerminal', activeResource); + } + + const terminalService = this.serviceContainer.get(ITerminalServiceFactory); await terminalService.createTerminalService(activeResource, 'Python').show(false); } } diff --git a/src/client/pythonEnvironments/creation/createEnvApi.ts b/src/client/pythonEnvironments/creation/createEnvApi.ts index ab0f0db317c3..b5df9232dd4b 100644 --- a/src/client/pythonEnvironments/creation/createEnvApi.ts +++ b/src/client/pythonEnvironments/creation/createEnvApi.ts @@ -72,7 +72,10 @@ export function registerCreateEnvironmentFeatures( ): Promise => { if (useEnvExtension()) { try { - const result = await executeCommand('python-envs.createAny'); + const result = await executeCommand( + 'python-envs.createAny', + options, + ); if (result) { return { path: result.environmentPath.path }; } diff --git a/src/client/repl/nativeRepl.ts b/src/client/repl/nativeRepl.ts index 6edd3cbd70a7..9b002655d714 100644 --- a/src/client/repl/nativeRepl.ts +++ b/src/client/repl/nativeRepl.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + // Native Repl class that holds instance of pythonServer and replController import { @@ -7,13 +10,12 @@ import { QuickPickItem, TextEditor, Uri, - workspace, WorkspaceFolder, } from 'vscode'; import { Disposable } from 'vscode-jsonrpc'; import { PVSC_EXTENSION_ID } from '../common/constants'; import { showQuickPick } from '../common/vscodeApis/windowApis'; -import { getWorkspaceFolders } from '../common/vscodeApis/workspaceApis'; +import { getWorkspaceFolders, onDidCloseNotebookDocument } from '../common/vscodeApis/workspaceApis'; import { PythonEnvironment } from '../pythonEnvironments/info'; import { createPythonServer, PythonServer } from './pythonServer'; import { executeNotebookCell, openInteractiveREPL, selectNotebookKernel } from './replCommandHandler'; @@ -69,11 +71,18 @@ export class NativeRepl implements Disposable { */ private watchNotebookClosed(): void { this.disposables.push( - workspace.onDidCloseNotebookDocument(async (nb) => { + onDidCloseNotebookDocument(async (nb) => { if (this.notebookDocument && nb.uri.toString() === this.notebookDocument.uri.toString()) { this.notebookDocument = undefined; this.newReplSession = true; await updateWorkspaceStateValue(NATIVE_REPL_URI_MEMENTO, undefined); + this.pythonServer.dispose(); + this.pythonServer = createPythonServer([this.interpreter.path as string], this.cwd); + this.disposables.push(this.pythonServer); + if (this.replController) { + this.replController.dispose(); + } + nativeRepl = undefined; } }), ); diff --git a/src/client/repl/pythonServer.ts b/src/client/repl/pythonServer.ts index 570433714f98..74e2d6ae7251 100644 --- a/src/client/repl/pythonServer.ts +++ b/src/client/repl/pythonServer.ts @@ -104,6 +104,7 @@ class PythonServerImpl implements PythonServer, Disposable { this.connection.sendNotification('exit'); this.disposables.forEach((d) => d.dispose()); this.connection.dispose(); + serverInstance = undefined; } } diff --git a/src/client/repl/replCommandHandler.ts b/src/client/repl/replCommandHandler.ts index 89ccbe11c337..f65580dd1e17 100644 --- a/src/client/repl/replCommandHandler.ts +++ b/src/client/repl/replCommandHandler.ts @@ -1,6 +1,4 @@ import { - commands, - window, NotebookController, NotebookEditor, ViewColumn, @@ -9,11 +7,13 @@ import { NotebookCellKind, NotebookEdit, WorkspaceEdit, - workspace, Uri, } from 'vscode'; import { getExistingReplViewColumn, getTabNameForUri } from './replUtils'; import { PVSC_EXTENSION_ID } from '../common/constants'; +import { showNotebookDocument } from '../common/vscodeApis/windowApis'; +import { openNotebookDocument, applyEdit } from '../common/vscodeApis/workspaceApis'; +import { executeCommand } from '../common/vscodeApis/commandApis'; /** * Function that opens/show REPL using IW UI. @@ -26,7 +26,7 @@ export async function openInteractiveREPL( let viewColumn = ViewColumn.Beside; if (notebookDocument instanceof Uri) { // Case where NotebookDocument is undefined, but workspace mementoURI exists. - notebookDocument = await workspace.openNotebookDocument(notebookDocument); + notebookDocument = await openNotebookDocument(notebookDocument); } else if (notebookDocument) { // Case where NotebookDocument (REPL document already exists in the tab) const existingReplViewColumn = getExistingReplViewColumn(notebookDocument); @@ -34,9 +34,9 @@ export async function openInteractiveREPL( } else if (!notebookDocument) { // Case where NotebookDocument doesnt exist, or // became outdated (untitled.ipynb created without Python extension knowing, effectively taking over original Python REPL's URI) - notebookDocument = await workspace.openNotebookDocument('jupyter-notebook'); + notebookDocument = await openNotebookDocument('jupyter-notebook'); } - const editor = await window.showNotebookDocument(notebookDocument!, { + const editor = await showNotebookDocument(notebookDocument!, { viewColumn, asRepl: 'Python REPL', preserveFocus, @@ -52,7 +52,7 @@ export async function openInteractiveREPL( return undefined; } - await commands.executeCommand('notebook.selectKernel', { + await executeCommand('notebook.selectKernel', { editor, id: notebookController.id, extension: PVSC_EXTENSION_ID, @@ -69,7 +69,7 @@ export async function selectNotebookKernel( notebookControllerId: string, extensionId: string, ): Promise { - await commands.executeCommand('notebook.selectKernel', { + await executeCommand('notebook.selectKernel', { notebookEditor, id: notebookControllerId, extension: extensionId, @@ -84,7 +84,7 @@ export async function executeNotebookCell(notebookEditor: NotebookEditor, code: const cellIndex = replOptions?.appendIndex ?? notebook.cellCount; await addCellToNotebook(notebook, cellIndex, code); // Execute the cell - commands.executeCommand('notebook.cell.execute', { + executeCommand('notebook.cell.execute', { ranges: [{ start: cellIndex, end: cellIndex + 1 }], document: notebook.uri, }); @@ -100,5 +100,5 @@ async function addCellToNotebook(notebookDocument: NotebookDocument, index: numb const notebookEdit = NotebookEdit.insertCells(index, [notebookCellData]); const workspaceEdit = new WorkspaceEdit(); workspaceEdit.set(notebookDocument!.uri, [notebookEdit]); - await workspace.applyEdit(workspaceEdit); + await applyEdit(workspaceEdit); } diff --git a/src/client/telemetry/pylance.ts b/src/client/telemetry/pylance.ts index 42d177488790..3d1ba05779dd 100644 --- a/src/client/telemetry/pylance.ts +++ b/src/client/telemetry/pylance.ts @@ -148,6 +148,32 @@ "failed" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } } */ +/* __GDPR__ + "language_server/completion_context_items" : { + "lsversion" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "context" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, + "count" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" } + } +*/ +/* __GDPR__ + "language_server/documentcolor_slow" : { + "bindcallcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "bindtime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "lsversion" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "parsecallcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "parsetime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "readfilecallcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "readfiletime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "resolvecallcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "resolvetime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "tokenizecallcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "tokenizetime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "totaltime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "typeevalcount" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "typeevaltime" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "failed" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } + } +*/ /* __GDPR__ "language_server/exception_intellicode" : { "lsversion" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, @@ -352,6 +378,9 @@ "language_server/settings" : { "addimportexactmatchonly" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, "aicodeactionsimplementabstractclasses" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, + "aiCodeActionsGenerateDocstring" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, + "aiCodeActionsGenerateSymbols" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, + "aiCodeActionsConvertFormatString" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, "autoimportcompletions" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, "autosearchpaths" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, "callArgumentNameInlayHints" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }, @@ -428,6 +457,16 @@ "lsversion" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } } */ +/* __GDPR__ + "language_server/mcp_tool" : { + "kind" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "duration" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "cancelled" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "cancellation_reason" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "lsversion" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" }, + "failed" : { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth" } + } +*/ /** * Telemetry event sent when LSP server crashes */ diff --git a/src/client/terminals/envCollectionActivation/service.ts b/src/client/terminals/envCollectionActivation/service.ts index 880053b03d1d..43b8ceeb8e06 100644 --- a/src/client/terminals/envCollectionActivation/service.ts +++ b/src/client/terminals/envCollectionActivation/service.ts @@ -221,10 +221,9 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ env.PS1 = await this.getPS1(shell, resource, env); const defaultPrependOptions = await this.getPrependOptions(); - const deactivate = await this.terminalDeactivateService.getScriptLocation(shell, resource); // Clear any previously set env vars from collection envVarCollection.clear(); - + const deactivate = await this.terminalDeactivateService.getScriptLocation(shell, resource); Object.keys(env).forEach((key) => { if (shouldSkip(key)) { return; diff --git a/src/client/terminals/envCollectionActivation/shellIntegrationService.ts b/src/client/terminals/envCollectionActivation/shellIntegrationService.ts index 71cfb18dd437..92bb98029892 100644 --- a/src/client/terminals/envCollectionActivation/shellIntegrationService.ts +++ b/src/client/terminals/envCollectionActivation/shellIntegrationService.ts @@ -15,6 +15,7 @@ import { IDisposableRegistry, IPersistentStateFactory } from '../../common/types import { sleep } from '../../common/utils/async'; import { traceError, traceVerbose } from '../../logging'; import { IShellIntegrationDetectionService } from '../types'; +import { isTrusted } from '../../common/vscodeApis/workspaceApis'; /** * This is a list of shells which support shell integration: @@ -151,10 +152,12 @@ export class ShellIntegrationDetectionService implements IShellIntegrationDetect * Creates a dummy terminal so that we are guaranteed a data write event for this shell type. */ private createDummyHiddenTerminal(shell: string) { - this.terminalManager.createTerminal({ - shellPath: shell, - hideFromUser: true, - }); + if (isTrusted()) { + this.terminalManager.createTerminal({ + shellPath: shell, + hideFromUser: true, + }); + } } } diff --git a/src/client/testing/testController/common/resultResolver.ts b/src/client/testing/testController/common/resultResolver.ts index 80e57edbabd2..82856627e0c9 100644 --- a/src/client/testing/testController/common/resultResolver.ts +++ b/src/client/testing/testController/common/resultResolver.ts @@ -17,7 +17,13 @@ import { Range, } from 'vscode'; import * as util from 'util'; -import { CoveragePayload, DiscoveredTestPayload, ExecutionTestPayload, ITestResultResolver } from './types'; +import { + CoveragePayload, + DiscoveredTestPayload, + ExecutionTestPayload, + FileCoverageMetrics, + ITestResultResolver, +} from './types'; import { TestProvider } from '../../types'; import { traceError, traceVerbose } from '../../../logging'; import { Testing } from '../../../common/utils/localize'; @@ -120,16 +126,25 @@ export class PythonResultResolver implements ITestResultResolver { } for (const [key, value] of Object.entries(payload.result)) { const fileNameStr = key; - const fileCoverageMetrics = value; + const fileCoverageMetrics: FileCoverageMetrics = value; const linesCovered = fileCoverageMetrics.lines_covered ? fileCoverageMetrics.lines_covered : []; // undefined if no lines covered const linesMissed = fileCoverageMetrics.lines_missed ? fileCoverageMetrics.lines_missed : []; // undefined if no lines missed + const executedBranches = fileCoverageMetrics.executed_branches; + const totalBranches = fileCoverageMetrics.total_branches; const lineCoverageCount = new TestCoverageCount( linesCovered.length, linesCovered.length + linesMissed.length, ); + let fileCoverage: FileCoverage; const uri = Uri.file(fileNameStr); - const fileCoverage = new FileCoverage(uri, lineCoverageCount); + if (totalBranches === -1) { + // branch coverage was not enabled and should not be displayed + fileCoverage = new FileCoverage(uri, lineCoverageCount); + } else { + const branchCoverageCount = new TestCoverageCount(executedBranches, totalBranches); + fileCoverage = new FileCoverage(uri, lineCoverageCount, branchCoverageCount); + } runInstance.addCoverage(fileCoverage); // create detailed coverage array for each file (only line coverage on detailed, not branch) diff --git a/src/client/testing/testController/common/types.ts b/src/client/testing/testController/common/types.ts index 7139788a8177..282379abdb85 100644 --- a/src/client/testing/testController/common/types.ts +++ b/src/client/testing/testController/common/types.ts @@ -222,6 +222,8 @@ export type FileCoverageMetrics = { lines_covered: number[]; // eslint-disable-next-line camelcase lines_missed: number[]; + executed_branches: number; + total_branches: number; }; export type ExecutionTestPayload = { diff --git a/src/client/testing/testController/common/utils.ts b/src/client/testing/testController/common/utils.ts index 9923d7ec3e12..c624ef034cf1 100644 --- a/src/client/testing/testController/common/utils.ts +++ b/src/client/testing/testController/common/utils.ts @@ -23,13 +23,6 @@ export function fixLogLinesNoTrailing(content: string): string { const lines = content.split(/\r?\n/g); return `${lines.join('\r\n')}`; } - -export const MESSAGE_ON_TESTING_OUTPUT_MOVE = - 'Starting now, all test run output will be sent to the Test Result panel,' + - ' while test discovery output will be sent to the "Python" output channel instead of the "Python Test Log" channel.' + - ' The "Python Test Log" channel will be deprecated within the next month.' + - ' See https://github.com/microsoft/vscode-python/wiki/New-Method-for-Output-Handling-in-Python-Testing for details.'; - export function createTestingDeferred(): Deferred { return createDeferred(); } diff --git a/src/client/testing/testController/controller.ts b/src/client/testing/testController/controller.ts index 98a7f909a8e2..fe384709c371 100644 --- a/src/client/testing/testController/controller.ts +++ b/src/client/testing/testController/controller.ts @@ -25,7 +25,7 @@ import { IExtensionSingleActivationService } from '../../activation/types'; import { ICommandManager, IWorkspaceService } from '../../common/application/types'; import * as constants from '../../common/constants'; import { IPythonExecutionFactory } from '../../common/process/types'; -import { IConfigurationService, IDisposableRegistry, ITestOutputChannel, Resource } from '../../common/types'; +import { IConfigurationService, IDisposableRegistry, Resource } from '../../common/types'; import { DelayedTrigger, IDelayedTrigger } from '../../common/utils/delayTrigger'; import { noop } from '../../common/utils/misc'; import { IInterpreterService } from '../../interpreter/contracts'; @@ -98,7 +98,6 @@ export class PythonTestController implements ITestController, IExtensionSingleAc @inject(ICommandManager) private readonly commandManager: ICommandManager, @inject(IPythonExecutionFactory) private readonly pythonExecFactory: IPythonExecutionFactory, @inject(ITestDebugLauncher) private readonly debugLauncher: ITestDebugLauncher, - @inject(ITestOutputChannel) private readonly testOutputChannel: ITestOutputChannel, @inject(IEnvironmentVariablesProvider) private readonly envVarsService: IEnvironmentVariablesProvider, ) { this.refreshCancellation = new CancellationTokenSource(); @@ -176,13 +175,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri); discoveryAdapter = new UnittestTestDiscoveryAdapter( this.configSettings, - this.testOutputChannel, resultResolver, this.envVarsService, ); executionAdapter = new UnittestTestExecutionAdapter( this.configSettings, - this.testOutputChannel, resultResolver, this.envVarsService, ); @@ -191,13 +188,11 @@ export class PythonTestController implements ITestController, IExtensionSingleAc resultResolver = new PythonResultResolver(this.testController, testProvider, workspace.uri); discoveryAdapter = new PytestTestDiscoveryAdapter( this.configSettings, - this.testOutputChannel, resultResolver, this.envVarsService, ); executionAdapter = new PytestTestExecutionAdapter( this.configSettings, - this.testOutputChannel, resultResolver, this.envVarsService, ); diff --git a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts index 71d71997c57e..04258ddbddf2 100644 --- a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts +++ b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts @@ -9,13 +9,12 @@ import { IPythonExecutionFactory, SpawnOptions, } from '../../../common/process/types'; -import { IConfigurationService, ITestOutputChannel } from '../../../common/types'; +import { IConfigurationService } from '../../../common/types'; import { createDeferred, Deferred } from '../../../common/utils/async'; import { EXTENSION_ROOT_DIR } from '../../../constants'; import { traceError, traceInfo, traceVerbose, traceWarn } from '../../../logging'; import { DiscoveredTestPayload, ITestDiscoveryAdapter, ITestResultResolver } from '../common/types'; import { - MESSAGE_ON_TESTING_OUTPUT_MOVE, createDiscoveryErrorPayload, createTestingDeferred, fixLogLinesNoTrailing, @@ -33,7 +32,6 @@ import { useEnvExtension, getEnvironment, runInBackground } from '../../../envEx export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { constructor( public configSettings: IConfigurationService, - private readonly outputChannel: ITestOutputChannel, private readonly resultResolver?: ITestResultResolver, private readonly envVarsService?: IEnvironmentVariablesProvider, ) {} @@ -112,7 +110,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { mutableEnv.PYTHONPATH = pythonPathCommand; mutableEnv.TEST_RUN_PIPE = discoveryPipeName; traceInfo( - `All environment variables set for pytest discovery, PYTHONPATH: ${JSON.stringify(mutableEnv.PYTHONPATH)}`, + `Environment variables set for pytest discovery: PYTHONPATH=${mutableEnv.PYTHONPATH}, TEST_RUN_PIPE=${mutableEnv.TEST_RUN_PIPE}`, ); // delete UUID following entire discovery finishing. @@ -138,15 +136,12 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { proc.stdout.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceInfo(out); - this.outputChannel?.append(out); }); proc.stderr.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceError(out); - this.outputChannel?.append(out); }); proc.onExit((code, signal) => { - this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`, @@ -165,7 +160,6 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { const spawnOptions: SpawnOptions = { cwd, throwOnStdErr: true, - outputChannel: this.outputChannel, env: mutableEnv, token, }; @@ -200,20 +194,16 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { // Take all output from the subprocess and add it to the test output channel. This will be the pytest output. // Displays output to user and ensure the subprocess doesn't run into buffer overflow. - // TODO: after a release, remove discovery output from the "Python Test Log" channel and send it to the "Python" channel instead. result?.proc?.stdout?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceInfo(out); - spawnOptions?.outputChannel?.append(`${out}`); }); result?.proc?.stderr?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceError(out); - spawnOptions?.outputChannel?.append(`${out}`); }); result?.proc?.on('exit', (code, signal) => { - this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}.`, diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index 3a824f79ac63..053c497c56e0 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -4,7 +4,7 @@ import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode'; import * as path from 'path'; import { ChildProcess } from 'child_process'; -import { IConfigurationService, ITestOutputChannel } from '../../../common/types'; +import { IConfigurationService } from '../../../common/types'; import { Deferred } from '../../../common/utils/async'; import { traceError, traceInfo, traceVerbose } from '../../../logging'; import { ExecutionTestPayload, ITestExecutionAdapter, ITestResultResolver } from '../common/types'; @@ -25,7 +25,6 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx export class PytestTestExecutionAdapter implements ITestExecutionAdapter { constructor( public configSettings: IConfigurationService, - private readonly outputChannel: ITestOutputChannel, private readonly resultResolver?: ITestResultResolver, private readonly envVarsService?: IEnvironmentVariablesProvider, ) {} @@ -138,15 +137,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { const testIdsFileName = await utils.writeTestIdsFile(testIds); mutableEnv.RUN_TEST_IDS_PIPE = testIdsFileName; traceInfo( - `All environment variables set for pytest execution, PYTHONPATH: ${JSON.stringify( - mutableEnv.PYTHONPATH, - )}`, + `Environment variables set for pytest execution: PYTHONPATH=${mutableEnv.PYTHONPATH}, TEST_RUN_PIPE=${mutableEnv.TEST_RUN_PIPE}, RUN_TEST_IDS_PIPE=${mutableEnv.RUN_TEST_IDS_PIPE}`, ); const spawnOptions: SpawnOptions = { cwd, throwOnStdErr: true, - outputChannel: this.outputChannel, env: mutableEnv, token: runInstance?.token, }; @@ -194,15 +190,12 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { proc.stdout.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); proc.stderr.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); proc.onExit((code, signal) => { - this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`, @@ -240,19 +233,15 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { // Take all output from the subprocess and add it to the test output channel. This will be the pytest output. // Displays output to user and ensure the subprocess doesn't run into buffer overflow. - // TODO: after a release, remove run output from the "Python Test Log" channel and send it to the "Test Result" channel instead. result?.proc?.stdout?.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); result?.proc?.stderr?.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); result?.proc?.on('exit', (code, signal) => { - this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`, diff --git a/src/client/testing/testController/unittest/testDiscoveryAdapter.ts b/src/client/testing/testController/unittest/testDiscoveryAdapter.ts index 7e478b25735a..23d70568687f 100644 --- a/src/client/testing/testController/unittest/testDiscoveryAdapter.ts +++ b/src/client/testing/testController/unittest/testDiscoveryAdapter.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { CancellationTokenSource, Uri } from 'vscode'; import { CancellationToken } from 'vscode-jsonrpc'; import { ChildProcess } from 'child_process'; -import { IConfigurationService, ITestOutputChannel } from '../../../common/types'; +import { IConfigurationService } from '../../../common/types'; import { EXTENSION_ROOT_DIR } from '../../../constants'; import { DiscoveredTestPayload, @@ -22,12 +22,7 @@ import { IPythonExecutionFactory, SpawnOptions, } from '../../../common/process/types'; -import { - MESSAGE_ON_TESTING_OUTPUT_MOVE, - createDiscoveryErrorPayload, - fixLogLinesNoTrailing, - startDiscoveryNamedPipe, -} from '../common/utils'; +import { createDiscoveryErrorPayload, fixLogLinesNoTrailing, startDiscoveryNamedPipe } from '../common/utils'; import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging'; import { getEnvironment, runInBackground, useEnvExtension } from '../../../envExt/api.internal'; @@ -37,7 +32,6 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { constructor( public configSettings: IConfigurationService, - private readonly outputChannel: ITestOutputChannel, private readonly resultResolver?: ITestResultResolver, private readonly envVarsService?: IEnvironmentVariablesProvider, ) {} @@ -79,7 +73,6 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { workspaceFolder: uri, command, cwd, - outChannel: this.outputChannel, token, }; @@ -128,15 +121,12 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { proc.stdout.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceInfo(out); - this.outputChannel?.append(out); }); proc.stderr.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); traceError(out); - this.outputChannel?.append(out); }); proc.onExit((code, signal) => { - this.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`, @@ -155,7 +145,6 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { token: options.token, cwd: options.cwd, throwOnStdErr: true, - outputChannel: options.outChannel, env: mutableEnv, }; @@ -187,22 +176,17 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { resultProc = result?.proc; // Displays output to user and ensure the subprocess doesn't run into buffer overflow. - // TODO: after a release, remove discovery output from the "Python Test Log" channel and send it to the "Python" channel instead. - // TODO: after a release, remove run output from the "Python Test Log" channel and send it to the "Test Result" channel instead. result?.proc?.stdout?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); - spawnOptions?.outputChannel?.append(`${out}`); traceInfo(out); }); result?.proc?.stderr?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); - spawnOptions?.outputChannel?.append(`${out}`); traceError(out); }); result?.proc?.on('exit', (code, signal) => { // if the child has testIds then this is a run request - spawnOptions?.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { // This occurs when we are running discovery diff --git a/src/client/testing/testController/unittest/testExecutionAdapter.ts b/src/client/testing/testController/unittest/testExecutionAdapter.ts index e46e8c436583..74572ea5c63c 100644 --- a/src/client/testing/testController/unittest/testExecutionAdapter.ts +++ b/src/client/testing/testController/unittest/testExecutionAdapter.ts @@ -4,7 +4,7 @@ import * as path from 'path'; import { CancellationTokenSource, DebugSessionOptions, TestRun, TestRunProfileKind, Uri } from 'vscode'; import { ChildProcess } from 'child_process'; -import { IConfigurationService, ITestOutputChannel } from '../../../common/types'; +import { IConfigurationService } from '../../../common/types'; import { Deferred, createDeferred } from '../../../common/utils/async'; import { EXTENSION_ROOT_DIR } from '../../../constants'; import { @@ -15,7 +15,7 @@ import { TestExecutionCommand, } from '../common/types'; import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging'; -import { MESSAGE_ON_TESTING_OUTPUT_MOVE, fixLogLinesNoTrailing } from '../common/utils'; +import { fixLogLinesNoTrailing } from '../common/utils'; import { EnvironmentVariables, IEnvironmentVariablesProvider } from '../../../common/variables/types'; import { ExecutionFactoryCreateWithEnvironmentOptions, @@ -35,7 +35,6 @@ import { getEnvironment, runInBackground, useEnvExtension } from '../../../envEx export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { constructor( public configSettings: IConfigurationService, - private readonly outputChannel: ITestOutputChannel, private readonly resultResolver?: ITestResultResolver, private readonly envVarsService?: IEnvironmentVariablesProvider, ) {} @@ -122,7 +121,6 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { cwd, profileKind, testIds, - outChannel: this.outputChannel, token: runInstance?.token, }; traceLog(`Running UNITTEST execution for the following test ids: ${testIds}`); @@ -140,7 +138,6 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { token: options.token, cwd: options.cwd, throwOnStdErr: true, - outputChannel: options.outChannel, env: mutableEnv, }; // Create the Python environment in which to execute the command. @@ -205,15 +202,12 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { proc.stdout.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); proc.stderr.on('data', (data) => { const out = utils.fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(out); - this.outputChannel?.append(out); }); proc.onExit((code, signal) => { - this.outputChannel?.append(utils.MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0) { traceError( `Subprocess exited unsuccessfully with exit code ${code} and signal ${signal} on workspace ${uri.fsPath}`, @@ -249,23 +243,18 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { resultProc = result?.proc; // Displays output to user and ensure the subprocess doesn't run into buffer overflow. - // TODO: after a release, remove discovery output from the "Python Test Log" channel and send it to the "Python" channel instead. - // TODO: after a release, remove run output from the "Python Test Log" channel and send it to the "Test Result" channel instead. result?.proc?.stdout?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(`${out}`); - spawnOptions?.outputChannel?.append(out); }); result?.proc?.stderr?.on('data', (data) => { const out = fixLogLinesNoTrailing(data.toString()); runInstance?.appendOutput(`${out}`); - spawnOptions?.outputChannel?.append(out); }); result?.proc?.on('exit', (code, signal) => { // if the child has testIds then this is a run request - spawnOptions?.outputChannel?.append(MESSAGE_ON_TESTING_OUTPUT_MOVE); if (code !== 0 && testIds) { // This occurs when we are running the test and there is an error which occurs. diff --git a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts index 3456a6252722..66cb9e0ae604 100644 --- a/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts +++ b/src/test/activation/jedi/jediAnalysisOptions.unit.test.ts @@ -74,6 +74,7 @@ suite('Jedi LSP - analysis Options', () => { expect(result.initializationOptions.hover.disable.keyword.all).to.deep.equal(true); expect(result.initializationOptions.workspace.extraPaths).to.deep.equal([]); expect(result.initializationOptions.workspace.symbols.maxSymbols).to.deep.equal(0); + expect(result.initializationOptions.semantic_tokens.enable).to.deep.equal(true); }); test('With interpreter path', async () => { diff --git a/src/test/common/configSettings/configSettings.pythonPath.unit.test.ts b/src/test/common/configSettings/configSettings.pythonPath.unit.test.ts index 29082bb5854f..8a2a90b288a3 100644 --- a/src/test/common/configSettings/configSettings.pythonPath.unit.test.ts +++ b/src/test/common/configSettings/configSettings.pythonPath.unit.test.ts @@ -17,6 +17,7 @@ import { PythonEnvironment } from '../../../client/pythonEnvironments/info'; import * as EnvFileTelemetry from '../../../client/telemetry/envFileTelemetry'; import { MockAutoSelectionService } from '../../mocks/autoSelector'; import { untildify } from '../../../client/common/helpers'; +import { MockExtensions } from '../../mocks/extensions'; suite('Python Settings - pythonPath', () => { class CustomPythonSettings extends PythonSettings { @@ -64,6 +65,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -78,6 +80,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -93,6 +96,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -110,6 +114,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -126,6 +131,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -145,6 +151,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -166,6 +173,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); configSettings.update(pythonSettings.object); @@ -184,6 +192,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); interpreterPathService.setup((i) => i.get(typemoq.It.isAny())).returns(() => 'custom'); pythonSettings.setup((p) => p.get(typemoq.It.isValue('defaultInterpreterPath'))).returns(() => 'python'); @@ -204,6 +213,7 @@ suite('Python Settings - pythonPath', () => { workspaceService.object, interpreterPathService.object, undefined, + new MockExtensions(), ); interpreterPathService.setup((i) => i.get(resource)).returns(() => 'python'); configSettings.update(pythonSettings.object); diff --git a/src/test/common/configSettings/configSettings.unit.test.ts b/src/test/common/configSettings/configSettings.unit.test.ts index 43fbf17e970e..65afc782d7bb 100644 --- a/src/test/common/configSettings/configSettings.unit.test.ts +++ b/src/test/common/configSettings/configSettings.unit.test.ts @@ -27,6 +27,7 @@ import { ITestingSettings } from '../../../client/testing/configuration/types'; import { MockAutoSelectionService } from '../../mocks/autoSelector'; import { MockMemento } from '../../mocks/mementos'; import { untildify } from '../../../client/common/helpers'; +import { MockExtensions } from '../../mocks/extensions'; suite('Python Settings', async () => { class CustomPythonSettings extends PythonSettings { @@ -40,6 +41,7 @@ suite('Python Settings', async () => { let config: TypeMoq.IMock; let expected: CustomPythonSettings; let settings: CustomPythonSettings; + let extensions: MockExtensions; setup(() => { sinon.stub(EnvFileTelemetry, 'sendSettingTelemetry').returns(); config = TypeMoq.Mock.ofType(undefined, TypeMoq.MockBehavior.Loose); @@ -47,6 +49,7 @@ suite('Python Settings', async () => { const workspaceService = new WorkspaceService(); const workspaceMemento = new MockMemento(); const globalMemento = new MockMemento(); + extensions = new MockExtensions(); const persistentStateFactory = new PersistentStateFactory(globalMemento, workspaceMemento); expected = new CustomPythonSettings( undefined, @@ -55,7 +58,8 @@ suite('Python Settings', async () => { new InterpreterPathService(persistentStateFactory, workspaceService, [], { remoteName: undefined, } as IApplicationEnvironment), - undefined, + { defaultLSType: LanguageServerType.Jedi }, + extensions, ); settings = new CustomPythonSettings( undefined, @@ -64,7 +68,8 @@ suite('Python Settings', async () => { new InterpreterPathService(persistentStateFactory, workspaceService, [], { remoteName: undefined, } as IApplicationEnvironment), - undefined, + { defaultLSType: LanguageServerType.Jedi }, + extensions, ); expected.defaultInterpreterPath = 'python'; }); @@ -226,7 +231,7 @@ suite('Python Settings', async () => { const values = [ { ls: LanguageServerType.Jedi, expected: LanguageServerType.Jedi, default: false }, { ls: LanguageServerType.JediLSP, expected: LanguageServerType.Jedi, default: false }, - { ls: LanguageServerType.Microsoft, expected: LanguageServerType.None, default: true }, + { ls: LanguageServerType.Microsoft, expected: LanguageServerType.Jedi, default: true }, { ls: LanguageServerType.Node, expected: LanguageServerType.Node, default: false }, { ls: LanguageServerType.None, expected: LanguageServerType.None, default: false }, ]; @@ -235,7 +240,48 @@ suite('Python Settings', async () => { testLanguageServer(v.ls, v.expected, v.default); }); - testLanguageServer('invalid' as LanguageServerType, LanguageServerType.None, true); + testLanguageServer('invalid' as LanguageServerType, LanguageServerType.Jedi, true); + }); + + function testPyreflySettings(pyreflyInstalled: boolean, pyreflyDisabled: boolean, languageServerDisabled: boolean) { + test(`pyrefly ${pyreflyInstalled ? 'installed' : 'not installed'} and ${ + pyreflyDisabled ? 'disabled' : 'enabled' + }`, () => { + if (pyreflyInstalled) { + extensions.extensionIdsToFind = ['meta.pyrefly']; + } else { + extensions.extensionIdsToFind = []; + } + config.setup((c) => c.get('pyrefly.disableLanguageServices')).returns(() => pyreflyDisabled); + + config + .setup((c) => c.get('languageServer')) + .returns(() => undefined) + .verifiable(TypeMoq.Times.once()); + + settings.update(config.object); + + if (languageServerDisabled) { + expect(settings.languageServer).to.equal(LanguageServerType.None); + } else { + expect(settings.languageServer).not.to.equal(LanguageServerType.None); + } + expect(settings.languageServerIsDefault).to.equal(true); + config.verifyAll(); + }); + } + + suite('pyrefly languageServer settings', async () => { + const values = [ + { pyreflyInstalled: true, pyreflyDisabled: false, languageServerDisabled: true }, + { pyreflyInstalled: true, pyreflyDisabled: true, languageServerDisabled: false }, + { pyreflyInstalled: false, pyreflyDisabled: true, languageServerDisabled: false }, + { pyreflyInstalled: false, pyreflyDisabled: false, languageServerDisabled: false }, + ]; + + values.forEach((v) => { + testPyreflySettings(v.pyreflyInstalled, v.pyreflyDisabled, v.languageServerDisabled); + }); }); function testExperiments(enabled: boolean) { diff --git a/src/test/extensionSettings.ts b/src/test/extensionSettings.ts index 66a77589a770..2d35dcb5f4ca 100644 --- a/src/test/extensionSettings.ts +++ b/src/test/extensionSettings.ts @@ -13,6 +13,7 @@ import { PersistentStateFactory } from '../client/common/persistentState'; import { IPythonSettings, Resource } from '../client/common/types'; import { PythonEnvironment } from '../client/pythonEnvironments/info'; import { MockMemento } from './mocks/mementos'; +import { MockExtensions } from './mocks/extensions'; export function getExtensionSettings(resource: Uri | undefined): IPythonSettings { const vscode = require('vscode') as typeof import('vscode'); @@ -41,6 +42,7 @@ export function getExtensionSettings(resource: Uri | undefined): IPythonSettings const workspaceMemento = new MockMemento(); const globalMemento = new MockMemento(); const persistentStateFactory = new PersistentStateFactory(globalMemento, workspaceMemento); + const extensions = new MockExtensions(); return pythonSettings.PythonSettings.getInstance( resource, new AutoSelectionService(), @@ -49,5 +51,6 @@ export function getExtensionSettings(resource: Uri | undefined): IPythonSettings remoteName: undefined, } as IApplicationEnvironment), undefined, + extensions, ); } diff --git a/src/test/mocks/extension.ts b/src/test/mocks/extension.ts new file mode 100644 index 000000000000..61d70eb5ee9e --- /dev/null +++ b/src/test/mocks/extension.ts @@ -0,0 +1,16 @@ +import { injectable } from 'inversify'; +import { Extension, ExtensionKind, Uri } from 'vscode'; + +@injectable() +export class MockExtension implements Extension { + id!: string; + extensionUri!: Uri; + extensionPath!: string; + isActive!: boolean; + packageJSON: any; + extensionKind!: ExtensionKind; + exports!: T; + activate(): Thenable { + throw new Error('Method not implemented.'); + } +} diff --git a/src/test/mocks/extensions.ts b/src/test/mocks/extensions.ts new file mode 100644 index 000000000000..efe9b6b8ca31 --- /dev/null +++ b/src/test/mocks/extensions.ts @@ -0,0 +1,23 @@ +import { injectable } from 'inversify'; +import { IExtensions } from '../../client/common/types'; +import { Extension, Event } from 'vscode'; +import { MockExtension } from './extension'; + +@injectable() +export class MockExtensions implements IExtensions { + extensionIdsToFind: unknown[] = []; + all: readonly Extension[] = []; + onDidChange: Event = () => { + throw new Error('Method not implemented'); + }; + getExtension(extensionId: string): Extension | undefined; + getExtension(extensionId: string): Extension | undefined; + getExtension(extensionId: unknown): import('vscode').Extension | undefined { + if (this.extensionIdsToFind.includes(extensionId)) { + return new MockExtension(); + } + } + determineExtensionFromCallStack(): Promise<{ extensionId: string; displayName: string }> { + throw new Error('Method not implemented.'); + } +} diff --git a/src/test/repl/nativeRepl.test.ts b/src/test/repl/nativeRepl.test.ts index 999bc656c64d..c05bb311a839 100644 --- a/src/test/repl/nativeRepl.test.ts +++ b/src/test/repl/nativeRepl.test.ts @@ -1,14 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + /* eslint-disable no-unused-expressions */ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as TypeMoq from 'typemoq'; import * as sinon from 'sinon'; -import { Disposable } from 'vscode'; +import { Disposable, EventEmitter, NotebookDocument, Uri } from 'vscode'; import { expect } from 'chai'; import { IInterpreterService } from '../../client/interpreter/contracts'; import { PythonEnvironment } from '../../client/pythonEnvironments/info'; -import { getNativeRepl, NativeRepl } from '../../client/repl/nativeRepl'; +import * as NativeReplModule from '../../client/repl/nativeRepl'; import * as persistentState from '../../client/common/persistentState'; +import * as PythonServer from '../../client/repl/pythonServer'; +import * as vscodeWorkspaceApis from '../../client/common/vscodeApis/workspaceApis'; +import * as replController from '../../client/repl/replController'; +import { executeCommand } from '../../client/common/vscodeApis/commandApis'; suite('REPL - Native REPL', () => { let interpreterService: TypeMoq.IMock; @@ -19,8 +26,20 @@ suite('REPL - Native REPL', () => { let setReplControllerSpy: sinon.SinonSpy; let getWorkspaceStateValueStub: sinon.SinonStub; let updateWorkspaceStateValueStub: sinon.SinonStub; + let createReplControllerStub: sinon.SinonStub; + let mockNotebookController: any; setup(() => { + (NativeReplModule as any).nativeRepl = undefined; + + mockNotebookController = { + id: 'mockController', + dispose: sinon.stub(), + updateNotebookAffinity: sinon.stub(), + createNotebookCellExecution: sinon.stub(), + variableProvider: null, + }; + interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) @@ -28,13 +47,13 @@ suite('REPL - Native REPL', () => { disposable = TypeMoq.Mock.ofType(); disposableArray = [disposable.object]; - setReplDirectoryStub = sinon.stub(NativeRepl.prototype as any, 'setReplDirectory').resolves(); // Stubbing private method - // Use a spy instead of a stub for setReplController - setReplControllerSpy = sinon.spy(NativeRepl.prototype, 'setReplController'); + createReplControllerStub = sinon.stub(replController, 'createReplController').returns(mockNotebookController); + setReplDirectoryStub = sinon.stub(NativeReplModule.NativeRepl.prototype as any, 'setReplDirectory').resolves(); + setReplControllerSpy = sinon.spy(NativeReplModule.NativeRepl.prototype, 'setReplController'); updateWorkspaceStateValueStub = sinon.stub(persistentState, 'updateWorkspaceStateValue').resolves(); }); - teardown(() => { + teardown(async () => { disposableArray.forEach((d) => { if (d) { d.dispose(); @@ -42,15 +61,16 @@ suite('REPL - Native REPL', () => { }); disposableArray = []; sinon.restore(); + executeCommand('workbench.action.closeActiveEditor'); }); test('getNativeRepl should call create constructor', async () => { - const createMethodStub = sinon.stub(NativeRepl, 'create'); + const createMethodStub = sinon.stub(NativeReplModule.NativeRepl, 'create'); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); - await getNativeRepl(interpreter as PythonEnvironment, disposableArray); + await NativeReplModule.getNativeRepl(interpreter as PythonEnvironment, disposableArray); expect(createMethodStub.calledOnce).to.be.true; }); @@ -61,7 +81,7 @@ suite('REPL - Native REPL', () => { .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); - const nativeRepl = await getNativeRepl(interpreter as PythonEnvironment, disposableArray); + const nativeRepl = await NativeReplModule.getNativeRepl(interpreter as PythonEnvironment, disposableArray); nativeRepl.sendToNativeRepl(undefined, false); @@ -74,7 +94,7 @@ suite('REPL - Native REPL', () => { .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); - const nativeRepl = await getNativeRepl(interpreter as PythonEnvironment, disposableArray); + const nativeRepl = await NativeReplModule.getNativeRepl(interpreter as PythonEnvironment, disposableArray); nativeRepl.sendToNativeRepl(undefined, false); @@ -87,12 +107,81 @@ suite('REPL - Native REPL', () => { .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); - await NativeRepl.create(interpreter as PythonEnvironment); + await NativeReplModule.NativeRepl.create(interpreter as PythonEnvironment); expect(setReplDirectoryStub.calledOnce).to.be.true; expect(setReplControllerSpy.calledOnce).to.be.true; + expect(createReplControllerStub.calledOnce).to.be.true; + }); + + test('watchNotebookClosed should clean up resources when notebook is closed', async () => { + const notebookCloseEmitter = new EventEmitter(); + sinon.stub(vscodeWorkspaceApis, 'onDidCloseNotebookDocument').callsFake((handler) => { + const disposable = notebookCloseEmitter.event(handler); + return disposable; + }); + + const mockPythonServer = { + onCodeExecuted: new EventEmitter().event, + execute: sinon.stub().resolves({ status: true, output: 'test output' }), + executeSilently: sinon.stub().resolves({ status: true, output: 'test output' }), + interrupt: sinon.stub(), + input: sinon.stub(), + checkValidCommand: sinon.stub().resolves(true), + dispose: sinon.stub(), + }; + + // Track the number of times createPythonServer was called + let createPythonServerCallCount = 0; + sinon.stub(PythonServer, 'createPythonServer').callsFake(() => { + // eslint-disable-next-line no-plusplus + createPythonServerCallCount++; + return mockPythonServer; + }); + + const interpreter = await interpreterService.object.getActiveInterpreter(); - setReplDirectoryStub.restore(); - setReplControllerSpy.restore(); + // Create NativeRepl directly to have more control over its state, go around private constructor. + const nativeRepl = new (NativeReplModule.NativeRepl as any)(); + nativeRepl.interpreter = interpreter as PythonEnvironment; + nativeRepl.cwd = '/helloJustMockedCwd/cwd'; + nativeRepl.pythonServer = mockPythonServer; + nativeRepl.replController = mockNotebookController; + nativeRepl.disposables = []; + + // Make the singleton point to our instance for testing + // Otherwise, it gets mixed with Native Repl from .create from test above. + (NativeReplModule as any).nativeRepl = nativeRepl; + + // Reset call count after initial setup + createPythonServerCallCount = 0; + + // Set notebookDocument to a mock document + const mockReplUri = Uri.parse('untitled:Untitled-999.ipynb?jupyter-notebook'); + const mockNotebookDocument = ({ + uri: mockReplUri, + toString: () => mockReplUri.toString(), + } as unknown) as NotebookDocument; + + nativeRepl.notebookDocument = mockNotebookDocument; + + // Create a mock notebook document for closing event with same URI + const closingNotebookDocument = ({ + uri: mockReplUri, + toString: () => mockReplUri.toString(), + } as unknown) as NotebookDocument; + + notebookCloseEmitter.fire(closingNotebookDocument); + await new Promise((resolve) => setTimeout(resolve, 50)); + + expect( + updateWorkspaceStateValueStub.calledWith(NativeReplModule.NATIVE_REPL_URI_MEMENTO, undefined), + 'updateWorkspaceStateValue should be called with NATIVE_REPL_URI_MEMENTO and undefined', + ).to.be.true; + expect(mockPythonServer.dispose.calledOnce, 'pythonServer.dispose() should be called once').to.be.true; + expect(createPythonServerCallCount, 'createPythonServer should be called to create a new server').to.equal(1); + expect(nativeRepl.notebookDocument, 'notebookDocument should be undefined after closing').to.be.undefined; + expect(nativeRepl.newReplSession, 'newReplSession should be set to true after closing').to.be.true; + expect(mockNotebookController.dispose.calledOnce, 'replController.dispose() should be called once').to.be.true; }); }); diff --git a/src/test/serviceRegistry.ts b/src/test/serviceRegistry.ts index a0919752cefd..382659b3f838 100644 --- a/src/test/serviceRegistry.ts +++ b/src/test/serviceRegistry.ts @@ -27,11 +27,10 @@ import { ICurrentProcess, IDisposableRegistry, IMemento, - ILogOutputChannel, IPathUtils, IsWindows, WORKSPACE_MEMENTO, - ITestOutputChannel, + ILogOutputChannel, } from '../client/common/types'; import { registerTypes as variableRegisterTypes } from '../client/common/variables/serviceRegistry'; import { EnvironmentActivationService } from '../client/interpreter/activation/service'; @@ -84,7 +83,7 @@ export class IocContainer { this.serviceManager.addSingletonInstance(ILogOutputChannel, stdOutputChannel); const testOutputChannel = new MockOutputChannel('Python Test - UnitTests'); this.disposables.push(testOutputChannel); - this.serviceManager.addSingletonInstance(ITestOutputChannel, testOutputChannel); + this.serviceManager.addSingletonInstance(ILogOutputChannel, testOutputChannel); this.serviceManager.addSingleton( IInterpreterAutoSelectionService, diff --git a/src/test/testing/common/managers/testConfigurationManager.unit.test.ts b/src/test/testing/common/managers/testConfigurationManager.unit.test.ts index c8b6085e599d..1b049d4f3fbe 100644 --- a/src/test/testing/common/managers/testConfigurationManager.unit.test.ts +++ b/src/test/testing/common/managers/testConfigurationManager.unit.test.ts @@ -5,7 +5,7 @@ import * as TypeMoq from 'typemoq'; import { OutputChannel, Uri } from 'vscode'; -import { IInstaller, ITestOutputChannel, Product } from '../../../../client/common/types'; +import { IInstaller, ILogOutputChannel, Product } from '../../../../client/common/types'; import { getNamesAndValues } from '../../../../client/common/utils/enum'; import { IServiceContainer } from '../../../../client/ioc/types'; import { UNIT_TEST_PRODUCTS } from '../../../../client/testing/common/constants'; @@ -41,7 +41,7 @@ suite('Unit Test Configuration Manager (unit)', () => { const installer = TypeMoq.Mock.ofType().object; const serviceContainer = TypeMoq.Mock.ofType(); serviceContainer - .setup((s) => s.get(TypeMoq.It.isValue(ITestOutputChannel))) + .setup((s) => s.get(TypeMoq.It.isValue(ILogOutputChannel))) .returns(() => outputChannel); serviceContainer .setup((s) => s.get(TypeMoq.It.isValue(ITestConfigSettingsService))) diff --git a/src/test/testing/common/testingAdapter.test.ts b/src/test/testing/common/testingAdapter.test.ts index ec19ce00f13f..dcd78dc23dba 100644 --- a/src/test/testing/common/testingAdapter.test.ts +++ b/src/test/testing/common/testingAdapter.test.ts @@ -11,7 +11,7 @@ import * as sinon from 'sinon'; import { PytestTestDiscoveryAdapter } from '../../../client/testing/testController/pytest/pytestDiscoveryAdapter'; import { ITestController, ITestResultResolver } from '../../../client/testing/testController/common/types'; import { IPythonExecutionFactory } from '../../../client/common/process/types'; -import { IConfigurationService, ITestOutputChannel } from '../../../client/common/types'; +import { IConfigurationService } from '../../../client/common/types'; import { IServiceContainer } from '../../../client/ioc/types'; import { EXTENSION_ROOT_DIR_FOR_TESTS, initialize } from '../../initialize'; import { traceError, traceLog } from '../../../client/logging'; @@ -22,7 +22,6 @@ import { PythonResultResolver } from '../../../client/testing/testController/com import { TestProvider } from '../../../client/testing/types'; import { PYTEST_PROVIDER, UNITTEST_PROVIDER } from '../../../client/testing/common/constants'; import { IEnvironmentVariablesProvider } from '../../../client/common/variables/types'; -import { createTypeMoq } from '../../mocks/helper'; import * as pixi from '../../../client/pythonEnvironments/common/environmentManagers/pixi'; suite('End to End Tests: test adapters', () => { @@ -32,7 +31,6 @@ suite('End to End Tests: test adapters', () => { let serviceContainer: IServiceContainer; let envVarsService: IEnvironmentVariablesProvider; let workspaceUri: Uri; - let testOutputChannel: typeMoq.IMock; let testController: TestController; let getPixiStub: sinon.SinonStub; const unittestProvider: TestProvider = UNITTEST_PROVIDER; @@ -116,24 +114,6 @@ suite('End to End Tests: test adapters', () => { envVarsService = serviceContainer.get(IEnvironmentVariablesProvider); // create objects that were not injected - - testOutputChannel = createTypeMoq(); - testOutputChannel - .setup((x) => x.append(typeMoq.It.isAny())) - .callback((appendVal: any) => { - traceLog('output channel - ', appendVal.toString()); - }) - .returns(() => { - // Whatever you need to return - }); - testOutputChannel - .setup((x) => x.appendLine(typeMoq.It.isAny())) - .callback((appendVal: any) => { - traceLog('output channel ', appendVal.toString()); - }) - .returns(() => { - // Whatever you need to return - }); }); teardown(() => { sinon.restore(); @@ -189,12 +169,7 @@ suite('End to End Tests: test adapters', () => { configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; // run unittest discovery - const discoveryAdapter = new UnittestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new UnittestTestDiscoveryAdapter(configService, resultResolver, envVarsService); await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => { // verification after discovery is complete @@ -234,12 +209,7 @@ suite('End to End Tests: test adapters', () => { workspaceUri = Uri.parse(rootPathLargeWorkspace); configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; // run discovery - const discoveryAdapter = new UnittestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new UnittestTestDiscoveryAdapter(configService, resultResolver, envVarsService); await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => { // 1. Check the status is "success" @@ -274,12 +244,7 @@ suite('End to End Tests: test adapters', () => { return Promise.resolve(); }; // run pytest discovery - const discoveryAdapter = new PytestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService); await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => { // verification after discovery is complete @@ -329,12 +294,7 @@ suite('End to End Tests: test adapters', () => { return Promise.resolve(); }; // run pytest discovery - const discoveryAdapter = new PytestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService); configService.getSettings(workspaceUri).testing.pytestArgs = []; await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => { @@ -418,12 +378,7 @@ suite('End to End Tests: test adapters', () => { return Promise.resolve(); }; // run pytest discovery - const discoveryAdapter = new PytestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService); configService.getSettings(workspaceUri).testing.pytestArgs = []; await discoveryAdapter.discoverTests(workspaceUri, pythonExecFactory).finally(() => { @@ -494,12 +449,7 @@ suite('End to End Tests: test adapters', () => { return Promise.resolve(); }; // run pytest discovery - const discoveryAdapter = new PytestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService); // set workspace to test workspace folder workspaceUri = Uri.parse(rootPathLargeWorkspace); @@ -548,12 +498,7 @@ suite('End to End Tests: test adapters', () => { workspaceUri = Uri.parse(rootPathSmallWorkspace); configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; // run execution - const executionAdapter = new UnittestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new UnittestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -628,12 +573,7 @@ suite('End to End Tests: test adapters', () => { configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; // run unittest execution - const executionAdapter = new UnittestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new UnittestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -703,12 +643,7 @@ suite('End to End Tests: test adapters', () => { configService.getSettings(workspaceUri).testing.pytestArgs = []; // run pytest execution - const executionAdapter = new PytestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new PytestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -776,6 +711,8 @@ suite('End to End Tests: test adapters', () => { // since only one test was run, the other test in the same file will have missed coverage lines assert.strictEqual(simpleFileCov.lines_covered.length, 3, 'Expected 1 line to be covered in even.py'); assert.strictEqual(simpleFileCov.lines_missed.length, 1, 'Expected 3 lines to be missed in even.py'); + assert.strictEqual(simpleFileCov.executed_branches, 1, 'Expected 1 branch to be executed in even.py'); + assert.strictEqual(simpleFileCov.total_branches, 2, 'Expected 2 branches in even.py'); return Promise.resolve(); }; @@ -783,12 +720,7 @@ suite('End to End Tests: test adapters', () => { workspaceUri = Uri.parse(rootPathCoverageWorkspace); configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; // run execution - const executionAdapter = new UnittestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new UnittestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -829,6 +761,8 @@ suite('End to End Tests: test adapters', () => { // since only one test was run, the other test in the same file will have missed coverage lines assert.strictEqual(simpleFileCov.lines_covered.length, 3, 'Expected 1 line to be covered in even.py'); assert.strictEqual(simpleFileCov.lines_missed.length, 1, 'Expected 3 lines to be missed in even.py'); + assert.strictEqual(simpleFileCov.executed_branches, 1, 'Expected 1 branch to be executed in even.py'); + assert.strictEqual(simpleFileCov.total_branches, 2, 'Expected 2 branches in even.py'); return Promise.resolve(); }; @@ -837,12 +771,7 @@ suite('End to End Tests: test adapters', () => { configService.getSettings(workspaceUri).testing.pytestArgs = []; // run pytest execution - const executionAdapter = new PytestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new PytestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -908,12 +837,7 @@ suite('End to End Tests: test adapters', () => { } // run pytest execution - const executionAdapter = new PytestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new PytestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -982,12 +906,7 @@ suite('End to End Tests: test adapters', () => { workspaceUri = Uri.parse(rootPathDiscoveryErrorWorkspace); configService.getSettings(workspaceUri).testing.unittestArgs = ['-s', '.', '-p', '*test*.py']; - const discoveryAdapter = new UnittestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new UnittestTestDiscoveryAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) @@ -1041,12 +960,7 @@ suite('End to End Tests: test adapters', () => { return Promise.resolve(); }; // run pytest discovery - const discoveryAdapter = new PytestTestDiscoveryAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const discoveryAdapter = new PytestTestDiscoveryAdapter(configService, resultResolver, envVarsService); // set workspace to test workspace folder workspaceUri = Uri.parse(rootPathDiscoveryErrorWorkspace); @@ -1102,12 +1016,7 @@ suite('End to End Tests: test adapters', () => { configService.getSettings(workspaceUri).testing.pytestArgs = []; // run pytest execution - const executionAdapter = new PytestTestExecutionAdapter( - configService, - testOutputChannel.object, - resultResolver, - envVarsService, - ); + const executionAdapter = new PytestTestExecutionAdapter(configService, resultResolver, envVarsService); const testRun = typeMoq.Mock.ofType(); testRun .setup((t) => t.token) diff --git a/src/test/testing/configuration.unit.test.ts b/src/test/testing/configuration.unit.test.ts index 6682abf019b8..98d19dca9cbc 100644 --- a/src/test/testing/configuration.unit.test.ts +++ b/src/test/testing/configuration.unit.test.ts @@ -10,7 +10,7 @@ import { IApplicationShell, ICommandManager, IWorkspaceService } from '../../cli import { IConfigurationService, IInstaller, - ITestOutputChannel, + ILogOutputChannel, IPythonSettings, Product, } from '../../client/common/types'; @@ -61,7 +61,7 @@ suite('Unit Tests - ConfigurationService', () => { configurationService.setup((c) => c.getSettings(workspaceUri)).returns(() => pythonSettings.object); serviceContainer - .setup((c) => c.get(typeMoq.It.isValue(ITestOutputChannel))) + .setup((c) => c.get(typeMoq.It.isValue(ILogOutputChannel))) .returns(() => outputChannel.object); serviceContainer.setup((c) => c.get(typeMoq.It.isValue(IInstaller))).returns(() => installer.object); serviceContainer diff --git a/src/test/testing/configurationFactory.unit.test.ts b/src/test/testing/configurationFactory.unit.test.ts index 0813e3f4aae1..493dfcc00b95 100644 --- a/src/test/testing/configurationFactory.unit.test.ts +++ b/src/test/testing/configurationFactory.unit.test.ts @@ -7,7 +7,7 @@ import { expect, use } from 'chai'; import * as chaiAsPromised from 'chai-as-promised'; import * as typeMoq from 'typemoq'; import { OutputChannel, Uri } from 'vscode'; -import { IInstaller, ITestOutputChannel, Product } from '../../client/common/types'; +import { IInstaller, ILogOutputChannel, Product } from '../../client/common/types'; import { IServiceContainer } from '../../client/ioc/types'; import { ITestConfigSettingsService, ITestConfigurationManagerFactory } from '../../client/testing/common/types'; import { TestConfigurationManagerFactory } from '../../client/testing/configurationFactory'; @@ -24,9 +24,7 @@ suite('Unit Tests - ConfigurationManagerFactory', () => { const installer = typeMoq.Mock.ofType(); const testConfigService = typeMoq.Mock.ofType(); - serviceContainer - .setup((c) => c.get(typeMoq.It.isValue(ITestOutputChannel))) - .returns(() => outputChannel.object); + serviceContainer.setup((c) => c.get(typeMoq.It.isValue(ILogOutputChannel))).returns(() => outputChannel.object); serviceContainer.setup((c) => c.get(typeMoq.It.isValue(IInstaller))).returns(() => installer.object); serviceContainer .setup((c) => c.get(typeMoq.It.isValue(ITestConfigSettingsService))) diff --git a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts index 157134cdf276..ec155ee3107d 100644 --- a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts +++ b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts @@ -8,7 +8,7 @@ import * as path from 'path'; import { Observable } from 'rxjs/Observable'; import * as fs from 'fs'; import * as sinon from 'sinon'; -import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types'; +import { IConfigurationService } from '../../../../client/common/types'; import { PytestTestDiscoveryAdapter } from '../../../../client/testing/testController/pytest/pytestDiscoveryAdapter'; import { IPythonExecutionFactory, @@ -29,7 +29,6 @@ suite('pytest test discovery adapter', () => { let adapter: PytestTestDiscoveryAdapter; let execService: typeMoq.IMock; let deferred: Deferred; - let outputChannel: typeMoq.IMock; let expectedPath: string; let uri: Uri; // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -72,7 +71,6 @@ suite('pytest test discovery adapter', () => { execService = typeMoq.Mock.ofType(); execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python')); - outputChannel = typeMoq.Mock.ofType(); const output = new Observable>(() => { /* no op */ @@ -117,7 +115,7 @@ suite('pytest test discovery adapter', () => { ); sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); - adapter = new PytestTestDiscoveryAdapter(configService, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configService); adapter.discoverTests(uri, execFactory.object); // add in await and trigger await deferred.promise; @@ -175,7 +173,7 @@ suite('pytest test discovery adapter', () => { return Promise.resolve(execService.object); }); - adapter = new PytestTestDiscoveryAdapter(configServiceNew, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configServiceNew); adapter.discoverTests(uri, execFactory.object); // add in await and trigger await deferred.promise; @@ -239,7 +237,7 @@ suite('pytest test discovery adapter', () => { return Promise.resolve(execService.object); }); - adapter = new PytestTestDiscoveryAdapter(configServiceNew, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configServiceNew); adapter.discoverTests(uri, execFactory.object); // add in await and trigger await deferred.promise; @@ -307,7 +305,7 @@ suite('pytest test discovery adapter', () => { return Promise.resolve(execService.object); }); - adapter = new PytestTestDiscoveryAdapter(configServiceNew, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configServiceNew); adapter.discoverTests(uri, execFactory.object); // add in await and trigger await deferred.promise; @@ -356,7 +354,7 @@ suite('pytest test discovery adapter', () => { ); sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); - adapter = new PytestTestDiscoveryAdapter(configService, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configService); const discoveryPromise = adapter.discoverTests(uri, execFactory.object, cancellationTokenSource.token); // Trigger cancellation before exec observable call finishes @@ -406,7 +404,7 @@ suite('pytest test discovery adapter', () => { ); sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); - adapter = new PytestTestDiscoveryAdapter(configService, outputChannel.object); + adapter = new PytestTestDiscoveryAdapter(configService); const discoveryPromise = adapter.discoverTests(uri, execFactory.object, cancellationTokenSource.token); // add in await and trigger diff --git a/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts b/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts index 413c0af9406d..e0401edc7b41 100644 --- a/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts +++ b/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts @@ -7,7 +7,7 @@ import * as typeMoq from 'typemoq'; import * as sinon from 'sinon'; import * as path from 'path'; import { Observable } from 'rxjs/Observable'; -import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types'; +import { IConfigurationService } from '../../../../client/common/types'; import { IPythonExecutionFactory, IPythonExecutionService, @@ -117,8 +117,7 @@ suite('pytest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); + adapter = new PytestTestExecutionAdapter(configService); const testIds = ['test1id', 'test2id']; adapter.runTests(uri, testIds, TestRunProfileKind.Run, testRun.object, execFactory.object); @@ -148,8 +147,7 @@ suite('pytest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); + adapter = new PytestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Run, testRun.object, execFactory.object); await deferred2.promise; @@ -207,8 +205,7 @@ suite('pytest test execution adapter', () => { isTestExecution: () => false, } as unknown) as IConfigurationService; const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); + adapter = new PytestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Run, testRun.object, execFactory.object); await deferred2.promise; @@ -263,8 +260,7 @@ suite('pytest test execution adapter', () => { } as any), ); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); + adapter = new PytestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Debug, testRun.object, execFactory.object, debugLauncher.object); await deferred3.promise; debugLauncher.verify( @@ -305,8 +301,7 @@ suite('pytest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); + adapter = new PytestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Coverage, testRun.object, execFactory.object); await deferred2.promise; diff --git a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts index 81480d08b2b8..ceee7f54f447 100644 --- a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts +++ b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts @@ -7,7 +7,7 @@ import * as sinon from 'sinon'; import * as path from 'path'; import { Observable } from 'rxjs'; import { IPythonExecutionFactory, IPythonExecutionService, Output } from '../../../client/common/process/types'; -import { IConfigurationService, ITestOutputChannel } from '../../../client/common/types'; +import { IConfigurationService } from '../../../client/common/types'; import { Deferred, createDeferred } from '../../../client/common/utils/async'; import { EXTENSION_ROOT_DIR } from '../../../client/constants'; import { ITestDebugLauncher } from '../../../client/testing/common/types'; @@ -121,7 +121,7 @@ suite('Execution Flow Run Adapters', () => { }); // define adapter and run tests - const testAdapter = createAdapter(adapter, configService, typeMoq.Mock.ofType().object); + const testAdapter = createAdapter(adapter, configService); await testAdapter.runTests( Uri.file(myTestPath), [], @@ -202,7 +202,7 @@ suite('Execution Flow Run Adapters', () => { }); // define adapter and run tests - const testAdapter = createAdapter(adapter, configService, typeMoq.Mock.ofType().object); + const testAdapter = createAdapter(adapter, configService); await testAdapter.runTests( Uri.file(myTestPath), [], @@ -221,9 +221,8 @@ suite('Execution Flow Run Adapters', () => { function createAdapter( adapterType: string, configService: IConfigurationService, - outputChannel: ITestOutputChannel, ): PytestTestExecutionAdapter | UnittestTestExecutionAdapter { - if (adapterType === 'pytest') return new PytestTestExecutionAdapter(configService, outputChannel); - if (adapterType === 'unittest') return new UnittestTestExecutionAdapter(configService, outputChannel); + if (adapterType === 'pytest') return new PytestTestExecutionAdapter(configService); + if (adapterType === 'unittest') return new UnittestTestExecutionAdapter(configService); throw Error('un-compatible adapter type'); } diff --git a/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts b/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts index 0a2cfad866d5..4dae070bccbe 100644 --- a/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts +++ b/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts @@ -9,7 +9,7 @@ import * as fs from 'fs'; import { CancellationTokenSource, Uri } from 'vscode'; import { Observable } from 'rxjs'; import * as sinon from 'sinon'; -import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types'; +import { IConfigurationService } from '../../../../client/common/types'; import { EXTENSION_ROOT_DIR } from '../../../../client/constants'; import { UnittestTestDiscoveryAdapter } from '../../../../client/testing/testController/unittest/testDiscoveryAdapter'; import { Deferred, createDeferred } from '../../../../client/common/utils/async'; @@ -25,7 +25,6 @@ import * as extapi from '../../../../client/envExt/api.internal'; suite('Unittest test discovery adapter', () => { let configService: IConfigurationService; - let outputChannel: typeMoq.IMock; let mockProc: MockChildProcess; let execService: typeMoq.IMock; let execFactory = typeMoq.Mock.ofType(); @@ -47,7 +46,6 @@ suite('Unittest test discovery adapter', () => { testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'] }, }), } as unknown) as IConfigurationService; - outputChannel = typeMoq.Mock.ofType(); // set up exec service with child process mockProc = new MockChildProcess('', ['']); @@ -94,7 +92,7 @@ suite('Unittest test discovery adapter', () => { }); test('DiscoverTests should send the discovery command to the test server with the correct args', async () => { - const adapter = new UnittestTestDiscoveryAdapter(configService, outputChannel.object); + const adapter = new UnittestTestDiscoveryAdapter(configService); adapter.discoverTests(uri, execFactory.object); const script = path.join(EXTENSION_ROOT_DIR, 'python_files', 'unittestadapter', 'discovery.py'); const argsExpected = [script, '--udiscovery', '-v', '-s', '.', '-p', 'test*']; @@ -137,7 +135,7 @@ suite('Unittest test discovery adapter', () => { testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'], cwd: expectedNewPath.toString() }, }), } as unknown) as IConfigurationService; - const adapter = new UnittestTestDiscoveryAdapter(configService, outputChannel.object); + const adapter = new UnittestTestDiscoveryAdapter(configService); adapter.discoverTests(uri, execFactory.object); const script = path.join(EXTENSION_ROOT_DIR, 'python_files', 'unittestadapter', 'discovery.py'); const argsExpected = [script, '--udiscovery', '-v', '-s', '.', '-p', 'test*']; @@ -189,7 +187,7 @@ suite('Unittest test discovery adapter', () => { ); sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); - const adapter = new UnittestTestDiscoveryAdapter(configService, outputChannel.object); + const adapter = new UnittestTestDiscoveryAdapter(configService); const discoveryPromise = adapter.discoverTests(uri, execFactory.object, cancellationTokenSource.token); // Trigger cancellation before exec observable call finishes @@ -239,7 +237,7 @@ suite('Unittest test discovery adapter', () => { ); sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); - const adapter = new UnittestTestDiscoveryAdapter(configService, outputChannel.object); + const adapter = new UnittestTestDiscoveryAdapter(configService); const discoveryPromise = adapter.discoverTests(uri, execFactory.object, cancellationTokenSource.token); // add in await and trigger diff --git a/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts b/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts index 688d6d398101..ab492736f0ad 100644 --- a/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts +++ b/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts @@ -7,7 +7,7 @@ import * as typeMoq from 'typemoq'; import * as sinon from 'sinon'; import * as path from 'path'; import { Observable } from 'rxjs/Observable'; -import { IConfigurationService, ITestOutputChannel } from '../../../../client/common/types'; +import { IConfigurationService } from '../../../../client/common/types'; import { IPythonExecutionFactory, IPythonExecutionService, @@ -116,8 +116,7 @@ suite('Unittest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); + adapter = new UnittestTestExecutionAdapter(configService); const testIds = ['test1id', 'test2id']; adapter.runTests(uri, testIds, TestRunProfileKind.Run, testRun.object, execFactory.object); @@ -147,8 +146,7 @@ suite('Unittest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); + adapter = new UnittestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Run, testRun.object, execFactory.object); await deferred2.promise; @@ -205,8 +203,7 @@ suite('Unittest test execution adapter', () => { isTestExecution: () => false, } as unknown) as IConfigurationService; const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); + adapter = new UnittestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Run, testRun.object, execFactory.object); await deferred2.promise; @@ -261,8 +258,7 @@ suite('Unittest test execution adapter', () => { } as any), ); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); + adapter = new UnittestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Debug, testRun.object, execFactory.object, debugLauncher.object); await deferred3.promise; debugLauncher.verify( @@ -302,8 +298,7 @@ suite('Unittest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const uri = Uri.file(myTestPath); - const outputChannel = typeMoq.Mock.ofType(); - adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); + adapter = new UnittestTestExecutionAdapter(configService); adapter.runTests(uri, [], TestRunProfileKind.Coverage, testRun.object, execFactory.object); await deferred2.promise; diff --git a/src/test/testing/testController/workspaceTestAdapter.unit.test.ts b/src/test/testing/testController/workspaceTestAdapter.unit.test.ts index 9a07d4451e85..aac07793ca66 100644 --- a/src/test/testing/testController/workspaceTestAdapter.unit.test.ts +++ b/src/test/testing/testController/workspaceTestAdapter.unit.test.ts @@ -6,7 +6,7 @@ import * as sinon from 'sinon'; import * as typemoq from 'typemoq'; import { TestController, TestItem, TestItemCollection, TestRun, Uri } from 'vscode'; -import { IConfigurationService, ITestOutputChannel } from '../../../client/common/types'; +import { IConfigurationService } from '../../../client/common/types'; import { UnittestTestDiscoveryAdapter } from '../../../client/testing/testController/unittest/testDiscoveryAdapter'; import { UnittestTestExecutionAdapter } from '../../../client/testing/testController/unittest/testExecutionAdapter'; // 7/7 import { WorkspaceTestAdapter } from '../../../client/testing/testController/workspaceTestAdapter'; @@ -25,7 +25,6 @@ suite('Workspace test adapter', () => { let discoverTestsStub: sinon.SinonStub; let sendTelemetryStub: sinon.SinonStub; - let outputChannel: typemoq.IMock; let telemetryEvent: { eventName: EventName; properties: Record }[] = []; let execFactory: typemoq.IMock; @@ -106,7 +105,6 @@ suite('Workspace test adapter', () => { discoverTestsStub = sinon.stub(UnittestTestDiscoveryAdapter.prototype, 'discoverTests'); sendTelemetryStub = sinon.stub(Telemetry, 'sendTelemetryEvent').callsFake(mockSendTelemetryEvent); - outputChannel = typemoq.Mock.ofType(); }); teardown(() => { @@ -119,8 +117,8 @@ suite('Workspace test adapter', () => { test('If discovery failed correctly create error node', async () => { discoverTestsStub.rejects(new Error('foo')); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const uriFoo = Uri.parse('foo'); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', @@ -158,8 +156,8 @@ suite('Workspace test adapter', () => { test("When discovering tests, the workspace test adapter should call the test discovery adapter's discoverTest method", async () => { discoverTestsStub.resolves(); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', testDiscoveryAdapter, @@ -184,8 +182,8 @@ suite('Workspace test adapter', () => { }), ); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', testDiscoveryAdapter, @@ -206,8 +204,8 @@ suite('Workspace test adapter', () => { test('If discovery succeeds, send a telemetry event with the "failed" key set to false', async () => { discoverTestsStub.resolves({ status: 'success' }); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', @@ -229,8 +227,8 @@ suite('Workspace test adapter', () => { test('If discovery failed, send a telemetry event with the "failed" key set to true, and add an error node to the test controller', async () => { discoverTestsStub.rejects(new Error('foo')); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', @@ -254,7 +252,6 @@ suite('Workspace test adapter', () => { let stubResultResolver: ITestResultResolver; let executionTestsStub: sinon.SinonStub; let sendTelemetryStub: sinon.SinonStub; - let outputChannel: typemoq.IMock; let runInstance: typemoq.IMock; let testControllerMock: typemoq.IMock; let telemetryEvent: { eventName: EventName; properties: Record }[] = []; @@ -331,7 +328,6 @@ suite('Workspace test adapter', () => { executionTestsStub = sandbox.stub(UnittestTestExecutionAdapter.prototype, 'runTests'); sendTelemetryStub = sandbox.stub(Telemetry, 'sendTelemetryEvent').callsFake(mockSendTelemetryEvent); - outputChannel = typemoq.Mock.ofType(); runInstance = typemoq.Mock.ofType(); const testProvider = 'pytest'; @@ -346,8 +342,8 @@ suite('Workspace test adapter', () => { sandbox.restore(); }); test('When executing tests, the right tests should be sent to be executed', async () => { - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', testDiscoveryAdapter, @@ -394,8 +390,8 @@ suite('Workspace test adapter', () => { }); test("When executing tests, the workspace test adapter should call the test execute adapter's executionTest method", async () => { - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', testDiscoveryAdapter, @@ -420,8 +416,8 @@ suite('Workspace test adapter', () => { }), ); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', testDiscoveryAdapter, @@ -442,8 +438,8 @@ suite('Workspace test adapter', () => { test('If execution failed correctly create error node', async () => { executionTestsStub.rejects(new Error('foo')); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest', @@ -480,8 +476,8 @@ suite('Workspace test adapter', () => { test('If execution failed, send a telemetry event with the "failed" key set to true, and add an error node to the test controller', async () => { executionTestsStub.rejects(new Error('foo')); - const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings, outputChannel.object); - const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings, outputChannel.object); + const testDiscoveryAdapter = new UnittestTestDiscoveryAdapter(stubConfigSettings); + const testExecutionAdapter = new UnittestTestExecutionAdapter(stubConfigSettings); const workspaceTestAdapter = new WorkspaceTestAdapter( 'unittest',