GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add testing for unittest execution python logic (#21022) · Al8a/vscode-python@983f05a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pythonFiles
    • tests/unittestadapter
      • test_execution.py
    • unittestadapter
      • execution.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pythonFiles/tests/unittestadapter/test_execution.py‎

Copy file name to clipboard
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import os
5+
import pathlib
6+
from typing import List
7+
8+
import pytest
9+
from unittestadapter.execution import parse_execution_cli_args, run_tests
10+
11+
TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data"
12+
13+
14+
@pytest.mark.parametrize(
15+
"args, expected",
16+
[
17+
(
18+
[
19+
"--port",
20+
"111",
21+
"--uuid",
22+
"fake-uuid",
23+
"--testids",
24+
"test_file.test_class.test_method",
25+
],
26+
(111, "fake-uuid", ["test_file.test_class.test_method"]),
27+
),
28+
(
29+
["--port", "111", "--uuid", "fake-uuid", "--testids", ""],
30+
(111, "fake-uuid", [""]),
31+
),
32+
(
33+
[
34+
"--port",
35+
"111",
36+
"--uuid",
37+
"fake-uuid",
38+
"--testids",
39+
"test_file.test_class.test_method",
40+
"-v",
41+
"-s",
42+
],
43+
(111, "fake-uuid", ["test_file.test_class.test_method"]),
44+
),
45+
],
46+
)
47+
def test_parse_execution_cli_args(args: List[str], expected: List[str]) -> None:
48+
"""The parse_execution_cli_args function should return values for the port, uuid, and testids arguments
49+
when passed as command-line options, and ignore unrecognized arguments.
50+
"""
51+
actual = parse_execution_cli_args(args)
52+
assert actual == expected
53+
54+
55+
def test_no_ids_run() -> None:
56+
"""This test runs on an empty array of test_ids, therefore it should return
57+
an empty dict for the result.
58+
"""
59+
start_dir: str = os.fspath(TEST_DATA_PATH)
60+
testids = []
61+
pattern = "discovery_simple*"
62+
actual = run_tests(start_dir, testids, pattern, None, "fake-uuid")
63+
assert actual
64+
assert all(item in actual for item in ("cwd", "status"))
65+
assert actual["status"] == "success"
66+
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
67+
if "result" in actual:
68+
assert len(actual["result"]) == 0
69+
else:
70+
raise AssertionError("actual['result'] is None")
71+
72+
73+
def test_single_ids_run() -> None:
74+
"""This test runs on a single test_id, therefore it should return
75+
a dict with a single key-value pair for the result.
76+
77+
This single test passes so the outcome should be 'success'.
78+
"""
79+
id = "discovery_simple.DiscoverySimple.test_one"
80+
actual = run_tests(
81+
os.fspath(TEST_DATA_PATH), [id], "discovery_simple*", None, "fake-uuid"
82+
)
83+
assert actual
84+
assert all(item in actual for item in ("cwd", "status"))
85+
assert actual["status"] == "success"
86+
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
87+
assert "result" in actual
88+
result = actual["result"]
89+
assert len(result) == 1
90+
assert id in result
91+
id_result = result[id]
92+
assert id_result is not None
93+
assert "outcome" in id_result
94+
assert id_result["outcome"] == "success"
Collapse file

‎pythonFiles/unittestadapter/execution.py‎

Copy file name to clipboardExpand all lines: pythonFiles/unittestadapter/execution.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ def run_tests(
206206

207207
if error is not None:
208208
payload["error"] = error
209+
else:
210+
status = TestExecutionStatus.success
209211

210212
payload["status"] = status
211213

212-
# print(f"payload: \n{json.dumps(payload, indent=4)}")
213-
214214
return payload
215215

216216

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.