Jeff
Jeff

Reputation: 850

VS CODE - Using the Test Explorer UI, how do I manually exclude/include test files

I am currently working on a SAM deployment project that includes the use of python for the Lambda. I created tests using pytest and runs great on my terminal. But its somehow hard to read on a terminal. Somehow I would like to have a testing like Visual Studio 2019's Test features, where its clean and neat, easy to review.

Using VS CODE (as I am working on python files), I installed the Test Explorer UI and support for python tests. As soon as I open it, it loads a ton of tests including the tests of the 3rd party libraries that I have on my deployment, and it clutters my test explorer. I do not want any of these tests anyway, but I do not know how to exclude them.

I also would want to only include specified test files manually (if that is possible). I do not have use for tons of tests auto-detected by the test explorer.

Upvotes: 2

Views: 5674

Answers (1)

Nikolay K
Nikolay K

Reputation: 3850

I know it's a late reply, but still, there is a solution. Since you're using pytest, I will give details for that test framework.

Python Test Explorer is aware of pytest arguments and most of the pytest arguments can be used to modify test discovery and execution in the same way as if pytest is used from the command line. So, for example, if you want to exclude some folder, you can use --ignore=relative/path/to/some/folder argument. See pytest documentation on --ignore option.

It works pretty much the same if you want only to include some tests or folders. There is no special option for that, just list files and folders you want to include, for example, relative/path/to/some/folder or relative/path/to/some/test_file.py. See pytest documentation on selecting tests.

Now, you have to tell Python Test Explorer what tests you want to include/exclude. This can be done with python.testing.pytestArgs option in settings.json. For example,

"python.testing.pytestArgs": ["--ignore=relative/path/to/some/folder"]

or

"python.testing.pytestArgs": [
    "relative/path/to/some/folder",
    "relative/path/to/some/test_file.py"
]

Full settings.json for the last example:

{
    "python.pythonPath": "python",
    "python.testing.pytestEnabled": true,
    "python.testing.pytestArgs": [
        "relative/path/to/some/folder",
        "relative/path/to/some/test_file.py"
    ]
}

Note: These settings also can be set in pytest.ini or other pytest configuration file. In that case, there is no need to modify settings.json.

Upvotes: 2

Related Questions