Resolving Pylint suggestions W0621: Redefining name

23 Views Asked by At

Am running pylint for my django project where i got the suggestions like W0621: Redefining name 'create_and_delete_client' from outer scope (line 18) (redefined-outer-name). Iam getting this suggestions in my test scripts files for using fixtures in test methods. so, i want to resolve it without using any disables.

This is my code

These are my fixtures.

@pytest.fixture
def create_and_delete_client():
    """
        method to create or delete client instances
    """
    client_axa=Clients.objects.create(name='AXA',osi_one_id=1)

    yield client_axa



@pytest.fixture
def create_and_delete_user():
    """
        method to create or delete user instances
    """
    role1=Role.objects.create(name='Super Admin')
    role2=Role.objects.create(name='Non Admin')
    role3=Role.objects.create(name='N/A')

    user1 = User.objects.create(username='jwilson',osi_one_id=9826,
                ad_username='auser1',first_name='JOHN',last_name='WILSON',role=role1)
    user2 = User.objects.create(username='ksingh',osi_one_id=9831,
                ad_username='auser3',first_name='KARAN',last_name='SINGH',role=role2)
    user3 = User.objects.create(username='N/A',ad_username='auser3',
                        first_name='X',last_name='X',role=role3)

    users={
        'user1':user1,
        'user2':user2,
        'user3':user3,
    }
    return users



this my one of the test script where am using both fixtures.


@pytest.mark.django_db
def test_admin_delete_client(create_and_delete_user,create_and_delete_client):
    """
        test case to delete client.
    """
    with pytest.warns(RuntimeWarning):
        client_axa=create_and_delete_client

        client=APIClient()

        url=f'/api/v1/clients/{client_axa.id}/'

        session_user=login_as_super_admin()

        headers = {"Authorization": session_user.get("auth_token")}

        response=client.delete(url, headers=headers)

        assert response.status_code == 200, \
        f"Expected status code 200 but got {response.status_code}"

        client_data=response.json()


        assert client_data['deleted_at'] is not None and client_data != ""

i tired by declaring global functions, and even using one more module to fixtures and calling them in test scripts but nothing worked

0

There are 0 best solutions below