jeudi 1 août 2019

Using fixtures with pytest: How to share fixtures and use their parameters in different functions

I am struggling with setting up my fixtures correctly in pytest. I always get a missing 1 required positional argument: error. This is what I am trying:

@pytest.mark.django_db
class TestCreate:

    @pytest.fixture(scope='class')
    def user(self):
        username = 'testuser'
        password = 'mypassword'

        user_data = {
            'username': username,
            'password': password,
        }

        return user_data

    def setup(self, user):
        """Setup for tests to create user and project

        """
        user_d = user
        print(user_d)
        username = user_d['username']


Basically I only want to access the dictionary in from my fixture. But I get E TypeError: setup() missing 1 required positional argument: 'user'

I seems Pytest doesn't have access to my fixtures?

Help is very much appreciated! Thanks in advance

Aucun commentaire:

Enregistrer un commentaire