GeezerVison is showing github.com — Unittest discovery using the new test adapter (#18253) · mitchell-as/vscode-python@854ef00
File treeExpand file treeCollapse file tree Open diff view settings test/testing/testController
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .vscode/settings.json +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | ".vscode test": true | 24 | 24 | }, | 25 | 25 | "[python]": { | 26 | | - "editor.formatOnSave": true | | 26 | + "editor.formatOnSave": true, | | 27 | + "editor.codeActionsOnSave": { | | 28 | + "source.organizeImports": true | | 29 | + } | 27 | 30 | }, | 28 | 31 | "[typescript]": { | 29 | 32 | "editor.defaultFormatter": "esbenp.prettier-vscode", | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +Rewrite support for unittest test discovery. |
Collapse file Copy file name to clipboardExpand all lines: package.nls.json +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 71 | 71 | "Common.moreInfo": "More Info", | 72 | 72 | "Common.and": "and", | 73 | 73 | "Common.ok": "Ok", | | 74 | + "Common.error": "Error", | 74 | 75 | "Common.install": "Install", | 75 | 76 | "Common.learnMore": "Learn more", | 76 | 77 | "Common.reportThisIssue": "Report this issue", | | 157 | 158 | "debug.pyramidEnterDevelopmentIniPathInvalidFilePathError": "Enter a valid file path", | 158 | 159 | "Testing.configureTests": "Configure Test Framework", | 159 | 160 | "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)", | 160 | 164 | "Common.openOutputPanel": "Show output", | 161 | 165 | "LanguageService.statusItem.name": "Python IntelliSense Status", | 162 | 166 | "LanguageService.statusItem.text": "Partial Mode", | |
Collapse file Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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) |
|