在python_bdd阶段之间转移一些状态的最佳实践是什么?

时间:2019-04-18 10:38:42

标签: python python-3.x bdd

每个人。当我开始以bdd样式编写一些测试时,有一个问题关于如何在python3.x的bdd(pytest_bdd)的各个阶段之间转移测试状态。我一直在寻找答案,并找到有关装置和字典的答案。某种...

@pytest.fixture
def data_through_stages():
    return {}

但是还有更多答案,例如仓库类的固定装置和物品...

@pytest.fixture
def context():
    class Context(object):
        pass

    return Context()
具有某些测试阶段的

或类,并将功能转移到子级测试类中,例如...

class AllSteps:

    @classmethod
    def given_step(cls):
        print("step 1")

    @classmethod
    def when_step(cls):
        print("step 2")

    @classmethod
    def then_step(cls):
        print("step 3")



class TestErrors(AllSteps):


    @staticmethod
    @given("some given discrption")
    def given():
        print(f"given step: {TestErrors.given_step()}")

    @staticmethod
    @when("some when discrption")
    def when(error):
        print("when step ", TestErrors.when_step())


    @staticmethod
    @then("some then discrption")
    def then():
        print("then step ", TestErrors.then_step())

    @staticmethod
    @scenario("./features/some_feature.feature", "some scenarion description")
    @pytest.mark.parametrize("error", [
        "no response",
        "internal error"
    ])
    def test_error(error):
        print(f"test error: {error}")

最后一个主要问题))哪种解决方案是最好的? 还有其他一些关于在pytest_bdd中的阶段之间转移状态的想法的问题。正如我所听到的那样,这是某种不良的代码风格吗?为什么会这样?

0 个答案:

没有答案
相关问题