每个人。当我开始以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中的阶段之间转移状态的想法的问题。正如我所听到的那样,这是某种不良的代码风格吗?为什么会这样?