kondratyev-nv / vscode-python-test-adapter

Python Test Adapter for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
MIT License
117 stars 27 forks source link

Test discovery per file/folder? #261

Open indigoviolet opened 3 years ago

indigoviolet commented 3 years ago

Currently test discovery takes a long time, but the usual pattern is that I'm adding tests in one file. Is it possible to optimize the "reload" function to be incremental?

kondratyev-nv commented 2 years ago

@indigoviolet Thank you for the issue! If you don't run all tests, you can update your test settings to discover tests only in specific folders. For example, for unittest (see docs https://docs.python.org/3/library/unittest.html#cmdoption-unittest-discover-s)

"python.testing.unittestArgs": [
    "-v",
    "-s",
    "./path/to/folder/you/are/working/with", <-- -s arg specifies a folder from which to discover tests
    "-p",
    "*test*.py"
],

or for pytest (see docs https://docs.pytest.org/en/6.2.x/usage.html#specifying-tests-selecting-tests)

"python.testing.pytestArgs": ["path/to/folder/you/are/working/with"]

Let me know if this helps.

indigoviolet commented 2 years ago

That can help, but it's quite inconvenient to change that setting each time I'm going to switch buffers and work on a test in another file. What I'm looking/hoping for is a flag like "Reload tests only in saved buffers", and each time I save a buffer, we rediscover the tests in that file and update the corresponding node in the main test tree.

k870611 commented 2 years ago

It not work for me, my settings.json is

{ "python.testing.unittestArgs": [ "-v", "-s", ".", "-p", "test*.py" ], "python.testing.pytestEnabled": false, "python.testing.nosetestsEnabled": false, "python.testing.unittestEnabled": true }

my test py are

test_a.py test_all_Commands.py test_AutomationTest.py test_BMC_Browser.py test_KVM.py test_Page_Element.py test_SSH_SCP.py

folder structure:

2021/08/21 11:12

. 2021/08/21 11:12 .. 2021/08/09 10:37 .vscode 2021/08/21 08:50 11,177,472 chromedriver.exe 2021/08/18 10:14 2,626 collect_value.py 2021/08/20 18:20 411 config.cfg 2021/08/21 10:53 14,730 template.py 2021/08/20 10:56 480 test.cmd 2021/08/21 11:22 6,014 test_a.py 2021/08/20 18:47 7,197 test_all_Commands.py 2021/08/21 10:34 7,859 test_AutomationTest.py 2021/08/20 18:20 4,125 test_BMC_Browser.py 2021/08/20 14:49 5,591 test_KVM.py 2021/08/20 14:49 4,673 test_Page_Element.py 2021/08/20 11:14 2,972 test_SSH_SCP.py 2021/08/21 09:36 tool 2021/08/20 18:20 utils 2021/08/20 10:47 293 init.py

and sidebar show as sshot-1

kondratyev-nv commented 2 years ago

@k870611 Have you tried changing -s argument from . to some subfolder, e.g. test_a? Also, it'd help if you provide additional details, like how should your expected result look like?

k870611 commented 2 years ago

like Python can put all the test in it py sshot-1

but Test Explorer is list all the test (not like python is put at sub) sshot-2

My folder structure is sshot-3