V
V
vaflya2019-06-04 10:50:06
Python
vaflya, 2019-06-04 10:50:06

How to prepare conditions for multiple test suites in Py.test?

There are several test kits:

  • -conftest.py
  • -test_profile.py
  • -test_messages.py
  • -test_app.py

each has a class and inside methods with tests, for example:
[test_profile.py]

import pytest
from conftest import *

class TestProfile
    def test_name(self):
        response = self.query.get('/profile/name', params={'1':'1'})
        content = response.json()
        print("Server response: " + str(content))
        assert response.status_code, 200

    def test_surname(self):
        response = self.query.post('/profile/surname, data={'key_id': '10'})
        assert response.status_code, 200

Actually the question is how to prepare a test user for all test suites 1 time?
Right now I'm using setup_class() and teardown_class() in each class in each file, but I'd like to create the user 1 time rather than 3 times.
I found something like this on google:
[conftest.py]

@pytest.fixture(autouse=True, scope='module')
def module_setup_teardown():
    print("MODULE SETUP!!!")
    yield
    print("MODULE TEARDOWN!!!")

After each set fulfills teardown and setup. Tried changing scope to session, didn't help.
ps Worries the most tearDown after all the tests to remove the user

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question