Skip to content

Commit 4a16008

Browse files
authored
Merge branch 'main' into discovery-cancellation
2 parents fdb21b9 + 9bc9f68 commit 4a16008

File tree

12 files changed

+179
-91
lines changed

12 files changed

+179
-91
lines changed

.github/workflows/stale-prs.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

build/test-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ pytest-json
3636

3737
# for pytest-describe related tests
3838
pytest-describe
39+
40+
# for pytest-ruff related tests
41+
pytest-ruff
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
# This file has no test, it's just a random script.
5+
6+
if __name__ == "__main__":
7+
print("Hello World!")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
5+
# This test passes.
6+
def test_function(): # test_marker--test_function
7+
assert 1 == 1

python_files/tests/pytestadapter/expected_discovery_test_output.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,3 +1577,94 @@
15771577
],
15781578
"id_": TEST_DATA_PATH_STR,
15791579
}
1580+
# This is the expected output for the folder_with_script folder when run with ruff
1581+
# └── .data
1582+
# └── folder_with_script
1583+
# └── script_random.py
1584+
# └── ruff
1585+
# └── test_simple.py
1586+
# └── ruff
1587+
# └── test_function
1588+
ruff_test_expected_output = {
1589+
"name": ".data",
1590+
"path": TEST_DATA_PATH_STR,
1591+
"type_": "folder",
1592+
"children": [
1593+
{
1594+
"name": "folder_with_script",
1595+
"path": os.fspath(TEST_DATA_PATH / "folder_with_script"),
1596+
"type_": "folder",
1597+
"id_": os.fspath(TEST_DATA_PATH / "folder_with_script"),
1598+
"children": [
1599+
{
1600+
"name": "script_random.py",
1601+
"path": os.fspath(TEST_DATA_PATH / "folder_with_script" / "script_random.py"),
1602+
"type_": "file",
1603+
"id_": os.fspath(TEST_DATA_PATH / "folder_with_script" / "script_random.py"),
1604+
"children": [
1605+
{
1606+
"name": "ruff",
1607+
"path": os.fspath(
1608+
TEST_DATA_PATH / "folder_with_script" / "script_random.py"
1609+
),
1610+
"lineno": "",
1611+
"type_": "test",
1612+
"id_": get_absolute_test_id(
1613+
"folder_with_script/script_random.py::ruff",
1614+
TEST_DATA_PATH / "folder_with_script" / "script_random.py",
1615+
),
1616+
"runID": get_absolute_test_id(
1617+
"folder_with_script/script_random.py::ruff",
1618+
TEST_DATA_PATH / "folder_with_script" / "script_random.py",
1619+
),
1620+
}
1621+
],
1622+
},
1623+
{
1624+
"name": "test_simple.py",
1625+
"path": os.fspath(TEST_DATA_PATH / "folder_with_script" / "test_simple.py"),
1626+
"type_": "file",
1627+
"id_": os.fspath(TEST_DATA_PATH / "folder_with_script" / "test_simple.py"),
1628+
"children": [
1629+
{
1630+
"name": "ruff",
1631+
"path": os.fspath(
1632+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py"
1633+
),
1634+
"lineno": "",
1635+
"type_": "test",
1636+
"id_": get_absolute_test_id(
1637+
"folder_with_script/test_simple.py::ruff",
1638+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py",
1639+
),
1640+
"runID": get_absolute_test_id(
1641+
"folder_with_script/test_simple.py::ruff",
1642+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py",
1643+
),
1644+
},
1645+
{
1646+
"name": "test_function",
1647+
"path": os.fspath(
1648+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py"
1649+
),
1650+
"lineno": find_test_line_number(
1651+
"test_function",
1652+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py",
1653+
),
1654+
"type_": "test",
1655+
"id_": get_absolute_test_id(
1656+
"folder_with_script/test_simple.py::test_function",
1657+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py",
1658+
),
1659+
"runID": get_absolute_test_id(
1660+
"folder_with_script/test_simple.py::test_function",
1661+
TEST_DATA_PATH / "folder_with_script" / "test_simple.py",
1662+
),
1663+
},
1664+
],
1665+
},
1666+
],
1667+
}
1668+
],
1669+
"id_": TEST_DATA_PATH_STR,
1670+
}

python_files/tests/pytestadapter/test_discovery.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,17 @@ def test_pytest_collect(file, expected_const):
195195
if actual_list is not None:
196196
actual_item = actual_list.pop(0)
197197
assert all(item in actual_item for item in ("status", "cwd", "error"))
198-
assert (
199-
actual_item.get("status") == "success"
200-
), f"Status is not 'success', error is: {actual_item.get('error')}"
198+
assert actual_item.get("status") == "success", (
199+
f"Status is not 'success', error is: {actual_item.get('error')}"
200+
)
201201
assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH)
202202
assert is_same_tree(
203203
actual_item.get("tests"),
204204
expected_const,
205205
["id_", "lineno", "name", "runID"],
206-
), f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_const, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
206+
), (
207+
f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_const, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
208+
)
207209

208210

209211
@pytest.mark.skipif(
@@ -232,13 +234,13 @@ def test_symlink_root_dir():
232234
actual_item = actual_list.pop(0)
233235
try:
234236
# Check if all requirements
235-
assert all(
236-
item in actual_item for item in ("status", "cwd", "error")
237-
), "Required keys are missing"
237+
assert all(item in actual_item for item in ("status", "cwd", "error")), (
238+
"Required keys are missing"
239+
)
238240
assert actual_item.get("status") == "success", "Status is not 'success'"
239-
assert actual_item.get("cwd") == os.fspath(
240-
destination
241-
), f"CWD does not match: {os.fspath(destination)}"
241+
assert actual_item.get("cwd") == os.fspath(destination), (
242+
f"CWD does not match: {os.fspath(destination)}"
243+
)
242244
assert actual_item.get("tests") == expected, "Tests do not match expected value"
243245
except AssertionError as e:
244246
# Print the actual_item in JSON format if an assertion fails
@@ -271,7 +273,9 @@ def test_pytest_root_dir():
271273
actual_item.get("tests"),
272274
expected_discovery_test_output.root_with_config_expected_output,
273275
["id_", "lineno", "name", "runID"],
274-
), f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_discovery_test_output.root_with_config_expected_output, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
276+
), (
277+
f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_discovery_test_output.root_with_config_expected_output, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
278+
)
275279

276280

277281
def test_pytest_config_file():
@@ -298,7 +302,9 @@ def test_pytest_config_file():
298302
actual_item.get("tests"),
299303
expected_discovery_test_output.root_with_config_expected_output,
300304
["id_", "lineno", "name", "runID"],
301-
), f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_discovery_test_output.root_with_config_expected_output, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
305+
), (
306+
f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_discovery_test_output.root_with_config_expected_output, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
307+
)
302308

303309

304310
def test_config_sub_folder():
@@ -329,3 +335,32 @@ def test_config_sub_folder():
329335
if actual_item.get("tests") is not None:
330336
tests: Any = actual_item.get("tests")
331337
assert tests.get("name") == "config_sub_folder"
338+
339+
340+
def test_ruff_plugin():
341+
"""Here the session node will be a subfolder of the workspace root and the test are in another subfolder.
342+
343+
This tests checks to see if test node path are under the session node and if so the
344+
session node is correctly updated to the common path.
345+
"""
346+
file_path = helpers.TEST_DATA_PATH / "folder_with_script"
347+
actual = helpers.runner(
348+
[os.fspath(file_path), "--collect-only", "--ruff"],
349+
)
350+
351+
assert actual
352+
actual_list: List[Dict[str, Any]] = actual
353+
if actual_list is not None:
354+
actual_item = actual_list.pop(0)
355+
assert all(item in actual_item for item in ("status", "cwd", "error"))
356+
assert actual_item.get("status") == "success", (
357+
f"Status is not 'success', error is: {actual_item.get('error')}"
358+
)
359+
assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH)
360+
assert is_same_tree(
361+
actual_item.get("tests"),
362+
expected_discovery_test_output.ruff_test_expected_output,
363+
["id_", "lineno", "name", "runID"],
364+
), (
365+
f"Tests tree does not match expected value. \n Expected: {json.dumps(expected_discovery_test_output.ruff_test_expected_output, indent=4)}. \n Actual: {json.dumps(actual_item.get('tests'), indent=4)}"
366+
)

python_files/tests/pytestadapter/test_execution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ def test_symlink_run():
258258
actual_item = actual_list.pop(0)
259259
try:
260260
# Check if all requirements
261-
assert all(
262-
item in actual_item for item in ("status", "cwd", "result")
263-
), "Required keys are missing"
261+
assert all(item in actual_item for item in ("status", "cwd", "result")), (
262+
"Required keys are missing"
263+
)
264264
assert actual_item.get("status") == "success", "Status is not 'success'"
265-
assert actual_item.get("cwd") == os.fspath(
266-
destination
267-
), f"CWD does not match: {os.fspath(destination)}"
265+
assert actual_item.get("cwd") == os.fspath(destination), (
266+
f"CWD does not match: {os.fspath(destination)}"
267+
)
268268
actual_result_dict = {}
269269
actual_result_dict.update(actual_item["result"])
270270
assert actual_result_dict == expected_const

python_files/tests/unittestadapter/test_discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ def test_simple_django_collect():
314314
if actual_list is not None:
315315
actual_item = actual_list.pop(0)
316316
assert all(item in actual_item for item in ("status", "cwd"))
317-
assert (
318-
actual_item.get("status") == "success"
319-
), f"Status is not 'success', error is: {actual_item.get('error')}"
317+
assert actual_item.get("status") == "success", (
318+
f"Status is not 'success', error is: {actual_item.get('error')}"
319+
)
320320
assert actual_item.get("cwd") == os.fspath(data_path)
321321
assert len(actual_item["tests"]["children"]) == 1
322322
assert actual_item["tests"]["children"][0]["children"][0]["id_"] == os.fsdecode(

python_files/unittestadapter/pvsc_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ def send_post_request(
350350
encoded = request.encode("utf-8")
351351
bytes_written = 0
352352
while bytes_written < len(encoded):
353-
print("writing more bytes!")
354353
segment = encoded[bytes_written : bytes_written + size]
355354
bytes_written += __writer.write(segment)
356355
__writer.flush()

python_files/vscode_pytest/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
import pathlib
1111
import sys
1212
import traceback
13-
from typing import (
14-
TYPE_CHECKING,
15-
Any,
16-
Dict,
17-
Generator,
18-
Literal,
19-
TypedDict,
20-
)
13+
from typing import TYPE_CHECKING, Any, Dict, Generator, Literal, TypedDict
2114

2215
import pytest
2316

0 commit comments

Comments
 (0)