小编Tam*_*wyn的帖子

Pytest:从父类继承固定装置

我有几个测试用例来测试基于 Flask/connexion 的 api 的端点。

现在我想将它们重新排序为类,因此有一个基类:

import pytest
from unittest import TestCase

# Get the connexion app with the database configuration
from app import app


class ConnexionTest(TestCase):
    """The base test providing auth and flask clients to other tests
    """
    @pytest.fixture(scope='session')
    def client(self):
        with app.app.test_client() as c:
            yield c
Run Code Online (Sandbox Code Playgroud)

现在我有另一个带有实际测试用例的课程:

import pytest
from ConnexionTest import ConnexionTest

class CreationTest(ConnexionTest):
    """Tests basic user creation
    """

    @pytest.mark.dependency()
    def test_createUser(self, client):
        self.generateKeys('admin')
        response = client.post('/api/v1/user/register', json={'userKey': self.cache['admin']['pubkey']})
        assert response.status_code == 200
Run Code Online (Sandbox Code Playgroud)

现在不幸的是我总是得到一个

TypeError: test_createUser() missing …
Run Code Online (Sandbox Code Playgroud)

python pytest flask connexion

9
推荐指数
1
解决办法
8285
查看次数

标签 统计

connexion ×1

flask ×1

pytest ×1

python ×1