Skip to content

Commit 55961e2

Browse files
committed
fix test
1 parent 369a6c0 commit 55961e2

File tree

2 files changed

+110
-81
lines changed

2 files changed

+110
-81
lines changed

python_files/tests/pytestadapter/expected_discovery_test_output.py

Lines changed: 80 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,88 +1733,96 @@
17331733
black_app_path = black_formatter_folder_path / "app.py"
17341734
black_test_app_path = black_formatter_folder_path / "test_app.py"
17351735
black_formatter_expected_output = {
1736-
"name": "2496-black-formatter",
1737-
"path": os.fspath(black_formatter_folder_path),
1736+
"name": ".data",
1737+
"path": TEST_DATA_PATH_STR,
17381738
"type_": "folder",
1739-
"id_": os.fspath(black_formatter_folder_path),
17401739
"children": [
17411740
{
1742-
"name": "app.py",
1743-
"path": os.fspath(black_app_path),
1744-
"type_": "file",
1745-
"id_": os.fspath(black_app_path),
1741+
"name": "2496-black-formatter",
1742+
"path": os.fspath(black_formatter_folder_path),
1743+
"type_": "folder",
1744+
"id_": os.fspath(black_formatter_folder_path),
17461745
"children": [
17471746
{
1748-
"name": "black",
1747+
"name": "app.py",
17491748
"path": os.fspath(black_app_path),
1750-
"lineno": "0",
1751-
"type_": "test",
1752-
"id_": get_absolute_test_id(
1753-
"2496-black-formatter/app.py::black",
1754-
black_app_path,
1755-
),
1756-
"runID": get_absolute_test_id(
1757-
"2496-black-formatter/app.py::black",
1758-
black_app_path,
1759-
),
1760-
}
1761-
],
1762-
},
1763-
{
1764-
"name": "test_app.py",
1765-
"path": os.fspath(black_test_app_path),
1766-
"type_": "file",
1767-
"id_": os.fspath(black_test_app_path),
1768-
"children": [
1769-
{
1770-
"name": "black",
1771-
"path": os.fspath(black_test_app_path),
1772-
"lineno": "0",
1773-
"type_": "test",
1774-
"id_": get_absolute_test_id(
1775-
"2496-black-formatter/test_app.py::black",
1776-
black_test_app_path,
1777-
),
1778-
"runID": get_absolute_test_id(
1779-
"2496-black-formatter/test_app.py::black",
1780-
black_test_app_path,
1781-
),
1782-
},
1783-
{
1784-
"name": "test_add",
1785-
"path": os.fspath(black_test_app_path),
1786-
"lineno": find_test_line_number(
1787-
"test_add",
1788-
black_test_app_path,
1789-
),
1790-
"type_": "test",
1791-
"id_": get_absolute_test_id(
1792-
"2496-black-formatter/test_app.py::test_add",
1793-
black_test_app_path,
1794-
),
1795-
"runID": get_absolute_test_id(
1796-
"2496-black-formatter/test_app.py::test_add",
1797-
black_test_app_path,
1798-
),
1749+
"type_": "file",
1750+
"id_": os.fspath(black_app_path),
1751+
"children": [
1752+
{
1753+
"name": "black",
1754+
"path": os.fspath(black_app_path),
1755+
"lineno": "0",
1756+
"type_": "test",
1757+
"id_": get_absolute_test_id(
1758+
"2496-black-formatter/app.py::black",
1759+
black_app_path,
1760+
),
1761+
"runID": get_absolute_test_id(
1762+
"2496-black-formatter/app.py::black",
1763+
black_app_path,
1764+
),
1765+
}
1766+
],
17991767
},
18001768
{
1801-
"name": "test_subtract",
1769+
"name": "test_app.py",
18021770
"path": os.fspath(black_test_app_path),
1803-
"lineno": find_test_line_number(
1804-
"test_subtract",
1805-
black_test_app_path,
1806-
),
1807-
"type_": "test",
1808-
"id_": get_absolute_test_id(
1809-
"2496-black-formatter/test_app.py::test_subtract",
1810-
black_test_app_path,
1811-
),
1812-
"runID": get_absolute_test_id(
1813-
"2496-black-formatter/test_app.py::test_subtract",
1814-
black_test_app_path,
1815-
),
1771+
"type_": "file",
1772+
"id_": os.fspath(black_test_app_path),
1773+
"children": [
1774+
{
1775+
"name": "black",
1776+
"path": os.fspath(black_test_app_path),
1777+
"lineno": "0",
1778+
"type_": "test",
1779+
"id_": get_absolute_test_id(
1780+
"2496-black-formatter/test_app.py::black",
1781+
black_test_app_path,
1782+
),
1783+
"runID": get_absolute_test_id(
1784+
"2496-black-formatter/test_app.py::black",
1785+
black_test_app_path,
1786+
),
1787+
},
1788+
{
1789+
"name": "test_add",
1790+
"path": os.fspath(black_test_app_path),
1791+
"lineno": find_test_line_number(
1792+
"test_add",
1793+
black_test_app_path,
1794+
),
1795+
"type_": "test",
1796+
"id_": get_absolute_test_id(
1797+
"2496-black-formatter/test_app.py::test_add",
1798+
black_test_app_path,
1799+
),
1800+
"runID": get_absolute_test_id(
1801+
"2496-black-formatter/test_app.py::test_add",
1802+
black_test_app_path,
1803+
),
1804+
},
1805+
{
1806+
"name": "test_subtract",
1807+
"path": os.fspath(black_test_app_path),
1808+
"lineno": find_test_line_number(
1809+
"test_subtract",
1810+
black_test_app_path,
1811+
),
1812+
"type_": "test",
1813+
"id_": get_absolute_test_id(
1814+
"2496-black-formatter/test_app.py::test_subtract",
1815+
black_test_app_path,
1816+
),
1817+
"runID": get_absolute_test_id(
1818+
"2496-black-formatter/test_app.py::test_subtract",
1819+
black_test_app_path,
1820+
),
1821+
},
1822+
],
18161823
},
18171824
],
1818-
},
1825+
}
18191826
],
1827+
"id_": TEST_DATA_PATH_STR,
18201828
}

python_files/tests/pytestadapter/test_discovery.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def test_parameterized_error_collect():
169169
"pytest_describe_plugin" + os.path.sep + "nested_describe.py",
170170
expected_discovery_test_output.expected_nested_describe_output,
171171
),
172-
("2496-black-formatter", expected_discovery_test_output.black_formatter_expected_output),
173172
],
174173
)
175174
def test_pytest_collect(file, expected_const):
@@ -338,15 +337,37 @@ def test_config_sub_folder():
338337
assert tests.get("name") == "config_sub_folder"
339338

340339

341-
def test_ruff_plugin():
342-
"""Here the session node will be a subfolder of the workspace root and the test are in another subfolder.
340+
@pytest.mark.parametrize(
341+
("file", "expected_const", "extra_arg"),
342+
[
343+
(
344+
"folder_with_script",
345+
expected_discovery_test_output.ruff_test_expected_output,
346+
"--ruff",
347+
),
348+
(
349+
"2496-black-formatter",
350+
expected_discovery_test_output.black_formatter_expected_output,
351+
"--black",
352+
),
353+
],
354+
)
355+
def test_plugin_collect(file, expected_const, extra_arg):
356+
"""Test pytest discovery on a folder with a plugin argument (e.g., --ruff, --black).
343357
344-
This tests checks to see if test node path are under the session node and if so the
345-
session node is correctly updated to the common path.
358+
Uses variables from expected_discovery_test_output.py to store the expected
359+
dictionary return. Only handles discovery and therefore already contains the arg
360+
--collect-only. All test discovery will succeed, be in the correct cwd, and match
361+
expected test output.
362+
363+
Keyword arguments:
364+
file -- a string with the file or folder to run pytest discovery on.
365+
expected_const -- the expected output from running pytest discovery on the file.
366+
extra_arg -- the extra plugin argument to pass (e.g., --ruff, --black)
346367
"""
347-
file_path = helpers.TEST_DATA_PATH / "folder_with_script"
368+
file_path = helpers.TEST_DATA_PATH / file
348369
actual = helpers.runner(
349-
[os.fspath(file_path), "--collect-only", "--ruff"],
370+
[os.fspath(file_path), "--collect-only", extra_arg],
350371
)
351372

352373
assert actual
@@ -360,8 +381,8 @@ def test_ruff_plugin():
360381
assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH)
361382
assert is_same_tree(
362383
actual_item.get("tests"),
363-
expected_discovery_test_output.ruff_test_expected_output,
384+
expected_const,
364385
["id_", "lineno", "name", "runID"],
365386
), (
366-
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)}"
387+
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)}"
367388
)

0 commit comments

Comments
 (0)