How to reset the test configuration of VS Code?

In VS Code there is a tab called testing which I want to reconfigure as I mistakenly configured it in wrong way while initially configuring it.

My current settings.json file:

 {
    "window.zoomLevel": 3,
    "workbench.iconTheme": "material-icon-theme",
}

I had a Django-based project for which I was creating the tests using pytest. For running those tests I went to configure the test section of VS Code.

example of test functions i wrote

While configuring the testing section of VS Code I chose the wrong directory, because of which I was not able to see my test class and functions to run the tests.

testing section of vscode not showing my test classes and functions due to wrong directory chose while configuration

Hence, I wanted to reset or reconfigure the testing section of vscode so that I can select the root directory of the project which should let me see the test classes and functions.

My pytest based testing classes and functions:

import pytest
from django.contrib.auth.models import User
from rest_framework import status

@pytest.mark.django_db
class TestCreateCollection:
    
    def test_if_user_annoymous_returns_401(self, api_client):
        
        response = api_client.post('/store/collections/', {'title':'a'})

        assert response.status_code == status.HTTP_401_UNAUTHORIZED # type: ignore

    def test_if_user_not_admin_returns_403(self, api_client):
        
        api_client.force_authenticate(user=User(is_staff=False))
        response = api_client.post('/store/collections/', {'title':'a'})

        assert response.status_code == status.HTTP_403_FORBIDDEN # type: ignore

    def test_if_data_is_invalid_returns_400(self, api_client):
        
        api_client.force_authenticate(user=User(is_staff=True))
        response = api_client.post('/store/collections/', {'title':''})

        assert response.status_code == status.HTTP_400_BAD_REQUEST # type: ignore
        assert response.data['title'] is not None # type: ignore

    def test_if_data_is_valid_returns_201(self, api_client):

        api_client.force_authenticate(user=User(is_staff=True))
        response = api_client.post('/store/collections/', {'title':'a'})

        assert response.status_code == status.HTTP_201_CREATED # type: ignore
        assert response.data['id'] > 0 # type: ignore

New contributor

Ravi Yadav is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

If you have the icon in the left sidebar for Testing,it may be because you have installed the extension Python.

I also set up a wrong configuration (unittest instead of pytest, in an incorrect folder).
After that I was unable to change again the settings (initial configuration GUI in VScode, that allow you to introduce the paths).

For me what it worked was:

  1. Reinstalling the Extension (after uninstalling it)

2. Later:

  • 2.1. Click into VScode “Settings”

  • 2.2. Search in the text_bar “python.test”.

  • 2.3 This will display all the features of python testing. I will go through all of them and click on the gear that appears when you hover over it. And click on “Reset setting”. (If you see, I work in the tab “workspace” but maybe you will have to reset it in the other tabs too (“USer” or “remote” tabs)

  • 2.4 Later close the project, open it again. And when you click again in the testing icon

It will ask you again about the configuration info.

It did not recognized my tests yet (pytest configuration).
So:

  1. This was because I needed to add a “init.py” file in the folder with the tests that were in subfolders, as described in the official Vscode documentation:

4 . I also needed to modify the “.vscode/settings.json” file of your project
And add those 2 lines

NOTE:
I am working with Conda environment in Remote, Linux, and Python 3.9.

Based on these tutorials official and unofficial I figured it out and now it works great!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật