diff --git a/pythonFiles/unittestadapter/discovery.py b/pythonFiles/unittestadapter/discovery.py index 7e07e45d1202..7525f33cda61 100644 --- a/pythonFiles/unittestadapter/discovery.py +++ b/pythonFiles/unittestadapter/discovery.py @@ -19,7 +19,7 @@ # If I use from utils then there will be an import error in test_discovery.py. from unittestadapter.utils import TestNode, build_test_tree, parse_unittest_args -DEFAULT_PORT = "45454" +DEFAULT_PORT = 45454 class PayloadDict(TypedDict): @@ -121,12 +121,18 @@ def post_response( start_dir, pattern, top_level_dir = parse_unittest_args(argv[index + 1 :]) - # Perform test discovery. testPort = int(os.environ.get("TEST_PORT", DEFAULT_PORT)) testUuid = os.environ.get("TEST_UUID") - # Post this discovery payload. + if testPort is DEFAULT_PORT: + print( + "Error[vscode-unittest]: TEST_PORT is not set.", + " TEST_UUID = ", + testUuid, + ) if testUuid is not None: + # Perform test discovery. payload = discover_tests(start_dir, pattern, top_level_dir, testUuid) + # Post this discovery payload. post_response(payload, testPort, testUuid) # Post EOT token. eot_payload: EOTPayloadDict = {"command_type": "discovery", "eot": True} diff --git a/pythonFiles/unittestadapter/execution.py b/pythonFiles/unittestadapter/execution.py index e5758118b951..2a22bfff3486 100644 --- a/pythonFiles/unittestadapter/execution.py +++ b/pythonFiles/unittestadapter/execution.py @@ -21,14 +21,13 @@ from typing_extensions import Literal, NotRequired, TypeAlias, TypedDict from unittestadapter.utils import parse_unittest_args -DEFAULT_PORT = "45454" - ErrorType = Union[ Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None] ] testPort = 0 testUuid = 0 START_DIR = "" +DEFAULT_PORT = 45454 class TestOutcomeEnum(str, enum.Enum): @@ -269,7 +268,8 @@ def post_response( run_test_ids_port_int = ( int(run_test_ids_port) if run_test_ids_port is not None else 0 ) - + if run_test_ids_port_int == 0: + print("Error[vscode-unittest]: RUN_TEST_IDS_PORT env var is not set.") # get data from socket test_ids_from_buffer = [] try: @@ -303,6 +303,19 @@ def post_response( testPort = int(os.environ.get("TEST_PORT", DEFAULT_PORT)) testUuid = os.environ.get("TEST_UUID") + if testPort is DEFAULT_PORT: + print( + "Error[vscode-unittest]: TEST_PORT is not set.", + " TEST_UUID = ", + testUuid, + ) + if testUuid is None: + print( + "Error[vscode-unittest]: TEST_UUID is not set.", + " TEST_PORT = ", + testPort, + ) + testUuid = "unknown" if test_ids_from_buffer: # Perform test execution. payload = run_tests( diff --git a/pythonFiles/vscode_pytest/__init__.py b/pythonFiles/vscode_pytest/__init__.py index 2fab4d77c2f8..8349e1aa893d 100644 --- a/pythonFiles/vscode_pytest/__init__.py +++ b/pythonFiles/vscode_pytest/__init__.py @@ -20,6 +20,8 @@ from testing_tools import socket_manager from typing_extensions import Literal, TypedDict +DEFAULT_PORT = 45454 + class TestData(TypedDict): """A general class that all test objects inherit from.""" @@ -683,8 +685,22 @@ def send_post_request( payload -- the payload data to be sent. cls_encoder -- a custom encoder if needed. """ - testPort = os.getenv("TEST_PORT", 45454) + testPort = os.getenv("TEST_PORT") testUuid = os.getenv("TEST_UUID") + if testPort is None: + print( + "Error[vscode-pytest]: TEST_PORT is not set.", + " TEST_UUID = ", + testUuid, + ) + testPort = DEFAULT_PORT + if testUuid is None: + print( + "Error[vscode-pytest]: TEST_UUID is not set.", + " TEST_PORT = ", + testPort, + ) + testUuid = "unknown" addr = ("localhost", int(testPort)) global __socket diff --git a/pythonFiles/vscode_pytest/run_pytest_script.py b/pythonFiles/vscode_pytest/run_pytest_script.py index c3720c8ab8d0..e60ee91f096e 100644 --- a/pythonFiles/vscode_pytest/run_pytest_script.py +++ b/pythonFiles/vscode_pytest/run_pytest_script.py @@ -28,6 +28,8 @@ run_test_ids_port_int = ( int(run_test_ids_port) if run_test_ids_port is not None else 0 ) + if run_test_ids_port_int == 0: + print("Error[vscode-pytest]: RUN_TEST_IDS_PORT env var is not set.") test_ids_from_buffer = [] try: client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts index 92bd9f04834e..09ca36849000 100644 --- a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts +++ b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts @@ -78,7 +78,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { mutableEnv.PYTHONPATH = pythonPathCommand; mutableEnv.TEST_UUID = uuid.toString(); mutableEnv.TEST_PORT = this.testServer.getPort().toString(); - + traceInfo(`All environment variables set for pytest discovery: ${JSON.stringify(mutableEnv)}`); const spawnOptions: SpawnOptions = { cwd, throwOnStdErr: true, diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index 5c04aabab845..fd61251d33fc 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -140,6 +140,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { // add port with run test ids to env vars const pytestRunTestIdsPort = await utils.startTestIdServer(testIds); mutableEnv.RUN_TEST_IDS_PORT = pytestRunTestIdsPort.toString(); + traceInfo(`All environment variables set for pytest execution: ${JSON.stringify(mutableEnv)}`); const spawnOptions: SpawnOptions = { cwd,