安装程序中的pytest固定装置

时间:2019-07-25 13:24:00

标签: python pytest fixtures

我有一个val gson = Gson() //convert a map to a data class inline fun <reified T> Map<String, Any>.toDataClass(): T { return convert() } //convert a data class to a map fun <T> T.serializeToMap(): Map<String, Any> { return convert() } //convert an object of type I to type O inline fun <I, reified O> I.convert(): O { val json = gson.toJson(this) return gson.fromJson(json, object : TypeToken<O>() {}.type) } 范围内的灯具。

function

是否可以通过某种方式调用import pytest @pytest.fixture(scope="function") def some_fixture(req): print "This is not the end" return "okay" 中的固定装置??

类似于以下代码段...

setup_method

我知道固定装置将与setup_method相同,但是我遇到了一个非常极端的情况,我希望固定装置可以在setup_method本身中执行。

1 个答案:

答案 0 :(得分:1)

您可以将setup_method标记为Fixture,然后在测试中调用它。

class TestOne(object):

    @pytest.fixture(scope="class")
    def setup_method(self, method, some_fixture): # this would give argument error
        print "okay"

    def test_one(self, setup_method):
        pass
相关问题