Skip to content

Commit 785ed68

Browse files
authored
add support for pytest describe (#24400)
fixes #21705
1 parent b1cb5c2 commit 785ed68

File tree

8 files changed

+385
-99
lines changed

8 files changed

+385
-99
lines changed

build/test-requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ django-stubs
3131
# for coverage
3232
coverage
3333
pytest-cov
34+
35+
# for pytest-describe related tests
36+
pytest-describe
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
def describe_A():
5+
def test_1(): # test_marker--test_1
6+
pass
7+
8+
def test_2(): # test_marker--test_2
9+
pass
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import pytest
5+
6+
7+
def describe_list():
8+
@pytest.fixture
9+
def list():
10+
return []
11+
12+
def describe_append():
13+
def add_empty(list): # test_marker--add_empty
14+
list.append("foo")
15+
list.append("bar")
16+
assert list == ["foo", "bar"]
17+
18+
def remove_empty(list): # test_marker--remove_empty
19+
try:
20+
list.remove("foo")
21+
except ValueError:
22+
pass
23+
24+
def describe_remove():
25+
@pytest.fixture
26+
def list():
27+
return ["foo", "bar"]
28+
29+
def removes(list): # test_marker--removes
30+
list.remove("foo")
31+
assert list == ["bar"]

python_files/tests/pytestadapter/expected_discovery_test_output.py

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,3 +1394,186 @@
13941394
],
13951395
"id_": TEST_DATA_PATH_STR,
13961396
}
1397+
# This is the expected output for the describe_only.py tests.
1398+
# └── describe_only.py
1399+
# └── describe_A
1400+
# └── test_1
1401+
# └── test_2
1402+
1403+
describe_only_path = TEST_DATA_PATH / "pytest_describe_plugin" / "describe_only.py"
1404+
pytest_describe_plugin_path = TEST_DATA_PATH / "pytest_describe_plugin"
1405+
1406+
expected_describe_only_output = {
1407+
"name": ".data",
1408+
"path": TEST_DATA_PATH_STR,
1409+
"type_": "folder",
1410+
"children": [
1411+
{
1412+
"name": "pytest_describe_plugin",
1413+
"path": os.fspath(pytest_describe_plugin_path),
1414+
"type_": "folder",
1415+
"id_": os.fspath(pytest_describe_plugin_path),
1416+
"children": [
1417+
{
1418+
"name": "describe_only.py",
1419+
"path": os.fspath(describe_only_path),
1420+
"type_": "file",
1421+
"id_": os.fspath(describe_only_path),
1422+
"children": [
1423+
{
1424+
"name": "describe_A",
1425+
"path": os.fspath(describe_only_path),
1426+
"type_": "class",
1427+
"children": [
1428+
{
1429+
"name": "test_1",
1430+
"path": os.fspath(describe_only_path),
1431+
"lineno": find_test_line_number(
1432+
"test_1",
1433+
describe_only_path,
1434+
),
1435+
"type_": "test",
1436+
"id_": get_absolute_test_id(
1437+
"pytest_describe_plugin/describe_only.py::describe_A::test_1",
1438+
describe_only_path,
1439+
),
1440+
"runID": get_absolute_test_id(
1441+
"pytest_describe_plugin/describe_only.py::describe_A::test_1",
1442+
describe_only_path,
1443+
),
1444+
},
1445+
{
1446+
"name": "test_2",
1447+
"path": os.fspath(describe_only_path),
1448+
"lineno": find_test_line_number(
1449+
"test_2",
1450+
describe_only_path,
1451+
),
1452+
"type_": "test",
1453+
"id_": get_absolute_test_id(
1454+
"pytest_describe_plugin/describe_only.py::describe_A::test_2",
1455+
describe_only_path,
1456+
),
1457+
"runID": get_absolute_test_id(
1458+
"pytest_describe_plugin/describe_only.py::describe_A::test_2",
1459+
describe_only_path,
1460+
),
1461+
},
1462+
],
1463+
"id_": "pytest_describe_plugin/describe_only.py::describe_A",
1464+
}
1465+
],
1466+
}
1467+
],
1468+
}
1469+
],
1470+
"id_": TEST_DATA_PATH_STR,
1471+
}
1472+
# This is the expected output for the nested_describe.py tests.
1473+
# └── nested_describe.py
1474+
# └── describe_list
1475+
# └── describe_append
1476+
# └── add_empty
1477+
# └── remove_empty
1478+
# └── describe_remove
1479+
# └── removes
1480+
nested_describe_path = TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py"
1481+
expected_nested_describe_output = {
1482+
"name": ".data",
1483+
"path": TEST_DATA_PATH_STR,
1484+
"type_": "folder",
1485+
"children": [
1486+
{
1487+
"name": "pytest_describe_plugin",
1488+
"path": os.fspath(pytest_describe_plugin_path),
1489+
"type_": "folder",
1490+
"id_": os.fspath(pytest_describe_plugin_path),
1491+
"children": [
1492+
{
1493+
"name": "nested_describe.py",
1494+
"path": os.fspath(nested_describe_path),
1495+
"type_": "file",
1496+
"id_": os.fspath(nested_describe_path),
1497+
"children": [
1498+
{
1499+
"name": "describe_list",
1500+
"path": os.fspath(nested_describe_path),
1501+
"type_": "class",
1502+
"children": [
1503+
{
1504+
"name": "describe_append",
1505+
"path": os.fspath(nested_describe_path),
1506+
"type_": "class",
1507+
"children": [
1508+
{
1509+
"name": "add_empty",
1510+
"path": os.fspath(nested_describe_path),
1511+
"lineno": find_test_line_number(
1512+
"add_empty",
1513+
nested_describe_path,
1514+
),
1515+
"type_": "test",
1516+
"id_": get_absolute_test_id(
1517+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::add_empty",
1518+
nested_describe_path,
1519+
),
1520+
"runID": get_absolute_test_id(
1521+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::add_empty",
1522+
nested_describe_path,
1523+
),
1524+
},
1525+
{
1526+
"name": "remove_empty",
1527+
"path": os.fspath(nested_describe_path),
1528+
"lineno": find_test_line_number(
1529+
"remove_empty",
1530+
nested_describe_path,
1531+
),
1532+
"type_": "test",
1533+
"id_": get_absolute_test_id(
1534+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::remove_empty",
1535+
nested_describe_path,
1536+
),
1537+
"runID": get_absolute_test_id(
1538+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::remove_empty",
1539+
nested_describe_path,
1540+
),
1541+
},
1542+
],
1543+
"id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_append",
1544+
},
1545+
{
1546+
"name": "describe_remove",
1547+
"path": os.fspath(nested_describe_path),
1548+
"type_": "class",
1549+
"children": [
1550+
{
1551+
"name": "removes",
1552+
"path": os.fspath(nested_describe_path),
1553+
"lineno": find_test_line_number(
1554+
"removes",
1555+
nested_describe_path,
1556+
),
1557+
"type_": "test",
1558+
"id_": get_absolute_test_id(
1559+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_remove::removes",
1560+
nested_describe_path,
1561+
),
1562+
"runID": get_absolute_test_id(
1563+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_remove::removes",
1564+
nested_describe_path,
1565+
),
1566+
}
1567+
],
1568+
"id_": "pytest_describe_plugin/nested_describe.py::describe_list::describe_remove",
1569+
},
1570+
],
1571+
"id_": "pytest_describe_plugin/nested_describe.py::describe_list",
1572+
}
1573+
],
1574+
}
1575+
],
1576+
}
1577+
],
1578+
"id_": TEST_DATA_PATH_STR,
1579+
}

python_files/tests/pytestadapter/expected_execution_test_output.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,91 @@
646646
"subtest": None,
647647
}
648648
}
649+
650+
651+
# This is the expected output for the pytest_describe_plugin/describe_only.py file.
652+
# └── pytest_describe_plugin
653+
# └── describe_only.py
654+
# └── describe_A
655+
# └── test_1: success
656+
# └── test_2: success
657+
658+
describe_only_expected_execution_output = {
659+
get_absolute_test_id(
660+
"pytest_describe_plugin/describe_only.py::describe_A::test_1",
661+
TEST_DATA_PATH / "pytest_describe_plugin" / "describe_only.py",
662+
): {
663+
"test": get_absolute_test_id(
664+
"pytest_describe_plugin/describe_only.py::describe_A::test_1",
665+
TEST_DATA_PATH / "pytest_describe_plugin" / "describe_only.py",
666+
),
667+
"outcome": "success",
668+
"message": None,
669+
"traceback": None,
670+
"subtest": None,
671+
},
672+
get_absolute_test_id(
673+
"pytest_describe_plugin/describe_only.py::describe_A::test_2",
674+
TEST_DATA_PATH / "pytest_describe_plugin" / "describe_only.py",
675+
): {
676+
"test": get_absolute_test_id(
677+
"pytest_describe_plugin/describe_only.py::describe_A::test_2",
678+
TEST_DATA_PATH / "pytest_describe_plugin" / "describe_only.py",
679+
),
680+
"outcome": "success",
681+
"message": None,
682+
"traceback": None,
683+
"subtest": None,
684+
},
685+
}
686+
687+
# This is the expected output for the pytest_describe_plugin/nested_describe.py file.
688+
# └── pytest_describe_plugin
689+
# └── nested_describe.py
690+
# └── describe_list
691+
# └── describe_append
692+
# └── add_empty: success
693+
# └── remove_empty: success
694+
# └── describe_remove
695+
# └── removes: success
696+
nested_describe_expected_execution_output = {
697+
get_absolute_test_id(
698+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::add_empty",
699+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
700+
): {
701+
"test": get_absolute_test_id(
702+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::add_empty",
703+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
704+
),
705+
"outcome": "success",
706+
"message": None,
707+
"traceback": None,
708+
"subtest": None,
709+
},
710+
get_absolute_test_id(
711+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::remove_empty",
712+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
713+
): {
714+
"test": get_absolute_test_id(
715+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_append::remove_empty",
716+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
717+
),
718+
"outcome": "success",
719+
"message": None,
720+
"traceback": None,
721+
"subtest": None,
722+
},
723+
get_absolute_test_id(
724+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_remove::removes",
725+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
726+
): {
727+
"test": get_absolute_test_id(
728+
"pytest_describe_plugin/nested_describe.py::describe_list::describe_remove::removes",
729+
TEST_DATA_PATH / "pytest_describe_plugin" / "nested_describe.py",
730+
),
731+
"outcome": "success",
732+
"message": None,
733+
"traceback": None,
734+
"subtest": None,
735+
},
736+
}

python_files/tests/pytestadapter/test_discovery.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ def test_parameterized_error_collect():
161161
"text_docstring.txt",
162162
expected_discovery_test_output.doctest_pytest_expected_output,
163163
),
164+
(
165+
"pytest_describe_plugin" + os.path.sep + "describe_only.py",
166+
expected_discovery_test_output.expected_describe_only_output,
167+
),
168+
(
169+
"pytest_describe_plugin" + os.path.sep + "nested_describe.py",
170+
expected_discovery_test_output.expected_nested_describe_output,
171+
),
164172
],
165173
)
166174
def test_pytest_collect(file, expected_const):

0 commit comments

Comments
 (0)