forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #20078 and closes #20085 (which is about the testing work to support this code) This logic now successfully works to discover the pytest repo tests. This branch takes into account all the previous comments made to the python discovery logic in the previous PR (located on my personal fork). Therefore this is a second round of edits on this code. It now works for the pytest library (discovers all the tests in the pytest library). --------- Co-authored-by: Brett Cannon <brcan@microsoft.com> Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
- Loading branch information
1 parent
7ac230c
commit ed06e55
Showing
22 changed files
with
1,380 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...pytestadapter/.data/double_nested_folder/nested_folder_one/nested_folder_two/test_nest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
# This test's id is double_nested_folder/nested_folder_one/nested_folder_two/test_nest.py::test_function. | ||
# This test passes. | ||
def test_function(): # test_marker--test_function | ||
assert 1 == 1 |
14 changes: 14 additions & 0 deletions
14
...ests/pytestadapter/.data/dual_level_nested_folder/nested_folder_one/test_bottom_folder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_t. | ||
# This test passes. | ||
def test_bottom_function_t(): # test_marker--test_bottom_function_t | ||
assert True | ||
|
||
|
||
# This test's id is dual_level_nested_folder/nested_folder_one/test_bottom_folder.py::test_bottom_function_f. | ||
# This test fails. | ||
def test_bottom_function_f(): # test_marker--test_bottom_function_f | ||
assert False |
14 changes: 14 additions & 0 deletions
14
pythonFiles/tests/pytestadapter/.data/dual_level_nested_folder/test_top_folder.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_t. | ||
# This test passes. | ||
def test_top_function_t(): # test_marker--test_top_function_t | ||
assert True | ||
|
||
|
||
# This test's id is dual_level_nested_folder/test_top_folder.py::test_top_function_f. | ||
# This test fails. | ||
def test_top_function_f(): # test_marker--test_top_function_f | ||
assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
# This file has no tests in it; the discovery will return an empty list of tests. | ||
def function_function(string): | ||
return string |
10 changes: 10 additions & 0 deletions
10
pythonFiles/tests/pytestadapter/.data/error_parametrize_discovery.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import pytest | ||
|
||
|
||
# This test has an error which will appear on pytest discovery. | ||
# This error is intentional and is meant to test pytest discovery error handling. | ||
@pytest.mark.parametrize("actual,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)]) | ||
def test_function(): | ||
assert True |
7 changes: 7 additions & 0 deletions
7
pythonFiles/tests/pytestadapter/.data/error_syntax_discovery.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
# This test has a syntax error. | ||
# This error is intentional and is meant to test pytest discovery error handling. | ||
def test_function() | ||
assert True |
10 changes: 10 additions & 0 deletions
10
pythonFiles/tests/pytestadapter/.data/parametrize_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import pytest | ||
|
||
|
||
# Testing pytest with parametrized tests. The first two pass, the third fails. | ||
# The tests ids are parametrize_tests.py::test_adding[3+5-8] and so on. | ||
@pytest.mark.parametrize( # test_marker--test_adding | ||
"actual, expected", [("3+5", 8), ("2+4", 6), ("6+9", 16)] | ||
) | ||
def test_adding(actual, expected): | ||
assert eval(actual) == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
|
||
# This test passes. | ||
def test_function(): # test_marker--test_function | ||
assert 1 == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This is a doctest test which passes #test_marker--text_docstring.txt | ||
>>> x = 3 | ||
>>> x | ||
3 |
21 changes: 21 additions & 0 deletions
21
pythonFiles/tests/pytestadapter/.data/unittest_folder/test_add.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import unittest | ||
|
||
|
||
def add(a, b): | ||
return a + b | ||
|
||
|
||
class TestAddFunction(unittest.TestCase): | ||
# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_positive_numbers. | ||
# This test passes. | ||
def test_add_positive_numbers(self): # test_marker--test_add_positive_numbers | ||
result = add(2, 3) | ||
self.assertEqual(result, 5) | ||
|
||
# This test's id is unittest_folder/test_add.py::TestAddFunction::test_add_negative_numbers. | ||
# This test passes. | ||
def test_add_negative_numbers(self): # test_marker--test_add_negative_numbers | ||
result = add(-2, -3) | ||
self.assertEqual(result, -5) |
25 changes: 25 additions & 0 deletions
25
pythonFiles/tests/pytestadapter/.data/unittest_folder/test_subtract.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import unittest | ||
|
||
|
||
def subtract(a, b): | ||
return a - b | ||
|
||
|
||
class TestSubtractFunction(unittest.TestCase): | ||
# This test's id is unittest_folder/test_subtract.py::TestSubtractFunction::test_subtract_positive_numbers. | ||
# This test passes. | ||
def test_subtract_positive_numbers( # test_marker--test_subtract_positive_numbers | ||
self, | ||
): | ||
result = subtract(5, 3) | ||
self.assertEqual(result, 2) | ||
|
||
# This test's id is unittest_folder/test_subtract.py::TestSubtractFunction::test_subtract_negative_numbers. | ||
# This test passes. | ||
def test_subtract_negative_numbers( # test_marker--test_subtract_negative_numbers | ||
self, | ||
): | ||
result = subtract(-2, -3) | ||
self.assertEqual(result, 1) |
17 changes: 17 additions & 0 deletions
17
pythonFiles/tests/pytestadapter/.data/unittest_pytest_same_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class TestExample(unittest.TestCase): | ||
# This test's id is unittest_pytest_same_file.py::TestExample::test_true_unittest. | ||
# Test type is unittest and this test passes. | ||
def test_true_unittest(self): # test_marker--test_true_unittest | ||
assert True | ||
|
||
|
||
# This test's id is unittest_pytest_same_file.py::test_true_pytest. | ||
# Test type is pytest and this test passes. | ||
def test_true_pytest(): # test_marker--test_true_pytest | ||
assert True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
Oops, something went wrong.