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 — Unittest discovery using the new test adapter (#18253) · mitchell-as/vscode-python@854ef00

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .vscode
    • settings.json
  • news/1 Enhancements
    • 17242.md
  • package.nls.json
  • pythonFiles
    • testing_tools
      • socket_manager.py
    • tests/unittestadapter
      • .data
        • discovery_empty.py
        • discovery_error
          • file_one.py
          • file_two.py
        • discovery_simple.py
        • utils_decorated_tree.py
        • utils_nested_cases
          • file_one.py
          • folder
            • __init__.py
            • file_two.py
        • utils_simple_cases.py
        • utils_simple_tree.py
      • __init__.py
      • conftest.py
      • helpers.py
      • test_discovery.py
      • test_utils.py
    • unittestadapter
      • __init__.py
      • discovery.py
      • utils.py
  • requirements.in
  • requirements.txt
  • src
    • client
      • common/utils
        • localize.ts
      • testing/testController
        • common
          • server.ts
          • testItemUtilities.ts
          • types.ts
          • utils.ts
        • controller.ts
        • unittest
          • testDiscoveryAdapter.ts
        • workspaceTestAdapter.ts
    • test/testing/testController
      • server.unit.test.ts
      • unittest
        • testDiscoveryAdapter.unit.test.ts
      • workspaceTestAdapter.unit.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.vscode/settings.json‎

Copy file name to clipboardExpand all lines: .vscode/settings.json
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
".vscode test": true
2424
},
2525
"[python]": {
26-
"editor.formatOnSave": true
26+
"editor.formatOnSave": true,
27+
"editor.codeActionsOnSave": {
28+
"source.organizeImports": true
29+
}
2730
},
2831
"[typescript]": {
2932
"editor.defaultFormatter": "esbenp.prettier-vscode",
Collapse file

‎news/1 Enhancements/17242.md‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rewrite support for unittest test discovery.
Collapse file

‎package.nls.json‎

Copy file name to clipboardExpand all lines: package.nls.json
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"Common.moreInfo": "More Info",
7272
"Common.and": "and",
7373
"Common.ok": "Ok",
74+
"Common.error": "Error",
7475
"Common.install": "Install",
7576
"Common.learnMore": "Learn more",
7677
"Common.reportThisIssue": "Report this issue",
@@ -157,6 +158,9 @@
157158
"debug.pyramidEnterDevelopmentIniPathInvalidFilePathError": "Enter a valid file path",
158159
"Testing.configureTests": "Configure Test Framework",
159160
"Testing.testNotConfigured": "No test framework configured.",
161+
"Testing.cancelUnittestDiscovery": "Canceled unittest test discovery",
162+
"Testing.errorUnittestDiscovery": "Unittest test discovery error",
163+
"Testing.seePythonOutput": "(see Output > Python)",
160164
"Common.openOutputPanel": "Show output",
161165
"LanguageService.statusItem.name": "Python IntelliSense Status",
162166
"LanguageService.statusItem.text": "Partial Mode",
Collapse file

‎pythonFiles/testing_tools/socket_manager.py‎

Copy file name to clipboard
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import socket
5+
import sys
6+
7+
8+
class SocketManager(object):
9+
"""Create a socket and connect to the given address.
10+
11+
The address is a (host: str, port: int) tuple.
12+
Example usage:
13+
14+
```
15+
with SocketManager(("localhost", 6767)) as sock:
16+
request = json.dumps(payload)
17+
result = s.socket.sendall(request.encode("utf-8"))
18+
```
19+
"""
20+
21+
def __init__(self, addr):
22+
self.addr = addr
23+
self.socket = None
24+
25+
def __enter__(self):
26+
self.socket = socket.socket(
27+
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP
28+
)
29+
if sys.platform == "win32":
30+
addr_use = socket.SO_EXCLUSIVEADDRUSE
31+
else:
32+
addr_use = socket.SO_REUSEADDR
33+
self.socket.setsockopt(socket.SOL_SOCKET, addr_use, 1)
34+
self.socket.connect(self.addr)
35+
36+
return self
37+
38+
def __exit__(self, *_):
39+
if self.socket:
40+
try:
41+
self.socket.shutdown(socket.SHUT_RDWR)
42+
except Exception:
43+
pass
44+
self.socket.close()
Collapse file

‎pythonFiles/tests/unittestadapter/.data/discovery_empty.py‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
6+
7+
class DiscoveryEmpty(unittest.TestCase):
8+
"""Test class for the test_empty_discovery test.
9+
10+
The discover_tests function should return a dictionary with a "success" status, no errors, and no test tree
11+
if unittest discovery was performed successfully but no tests were found.
12+
"""
13+
14+
def something(self) -> bool:
15+
return True
Collapse file

‎pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
6+
import something_else # type: ignore
7+
8+
9+
class DiscoveryErrorOne(unittest.TestCase):
10+
"""Test class for the test_error_discovery test.
11+
12+
The discover_tests function should return a dictionary with an "error" status, the discovered tests, and a list of errors
13+
if unittest discovery failed at some point.
14+
"""
15+
16+
def test_one(self) -> None:
17+
self.assertGreater(2, 1)
18+
19+
def test_two(self) -> None:
20+
self.assertNotEqual(2, 1)
Collapse file

‎pythonFiles/tests/unittestadapter/.data/discovery_error/file_two.py‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
6+
7+
class DiscoveryErrorTwo(unittest.TestCase):
8+
"""Test class for the test_error_discovery test.
9+
10+
The discover_tests function should return a dictionary with an "error" status, the discovered tests, and a list of errors
11+
if unittest discovery failed at some point.
12+
"""
13+
14+
def test_one(self) -> None:
15+
self.assertGreater(2, 1)
16+
17+
def test_two(self) -> None:
18+
self.assertNotEqual(2, 1)
Collapse file

‎pythonFiles/tests/unittestadapter/.data/discovery_simple.py‎

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
6+
7+
class DiscoverySimple(unittest.TestCase):
8+
"""Test class for the test_simple_discovery test.
9+
10+
The discover_tests function should return a dictionary with a "success" status, no errors, and a test tree
11+
if unittest discovery was performed successfully.
12+
"""
13+
14+
def test_one(self) -> None:
15+
self.assertGreater(2, 1)
16+
17+
def test_two(self) -> None:
18+
self.assertNotEqual(2, 1)
Collapse file

‎pythonFiles/tests/unittestadapter/.data/utils_decorated_tree.py‎

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
from functools import wraps
6+
7+
8+
def my_decorator(f):
9+
@wraps(f)
10+
def wrapper(*args, **kwds):
11+
print("Calling decorated function")
12+
return f(*args, **kwds)
13+
14+
return wrapper
15+
16+
17+
class TreeOne(unittest.TestCase):
18+
"""Test class for the test_build_decorated_tree test.
19+
20+
build_test_tree should build a test tree with these test cases.
21+
"""
22+
23+
@my_decorator
24+
def test_one(self) -> None:
25+
self.assertGreater(2, 1)
26+
27+
@my_decorator
28+
def test_two(self) -> None:
29+
self.assertNotEqual(2, 1)
Collapse file

‎pythonFiles/tests/unittestadapter/.data/utils_nested_cases/file_one.py‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
6+
7+
class CaseTwoFileOne(unittest.TestCase):
8+
"""Test class for the test_nested_test_cases test.
9+
10+
get_test_case should return tests from the test suites in this folder.
11+
"""
12+
13+
def test_one(self) -> None:
14+
self.assertGreater(2, 1)
15+
16+
def test_two(self) -> None:
17+
self.assertNotEqual(2, 1)

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.