[英]How to use fixtures in a Class which is inherting UnitTest class in python pytest
import pytest
@pytest.fixture(scope="session")
def client():
env_name = 'FLASK_ENV'
return env_name
@pytest.fixture(scope="session")
def client_1():
env_name = 'FLASK_ENV_1'
return env_name
import pytest
import unittest
@pytest.mark.usefixtures("client")
@pytest.mark.usefixtures("client_1")
class TestStaticPages(unittest.TestCase):
@classmethod
def setUpClass(self):
self.value = "ABC"
def test_base_route(self, client, client_1):
response = client
assert response == 'FLASK_ENV'
assert client_1 == 'FLASK_ENV_1'
我是 Python 中 UnitTest 的新手。 當我嘗試在測試類中使用固定裝置時,它失敗了。 你能幫我解決這個問題嗎? 提前致謝。
不幸的是,我認為沒有辦法做到這一點。 在pytest 文檔中,指出:
unittest.TestCase 方法不能直接接收夾具參數作為實現,這可能會影響運行通用 unittest.TestCase 測試套件的能力。
因此,您的client
和client_1
函數可以在測試用例運行時調用,但您無法訪問它們的返回值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.