Python capsys损坏,使用pytest bdd时可能会对一个步骤进行两次计算?
我想断言,使用pytest bdd将某些内容写入标准输出。这是我的Python capsys损坏,使用pytest bdd时可能会对一个步骤进行两次计算?,python,python-3.x,bdd,pytest,Python,Python 3.x,Bdd,Pytest,我想断言,使用pytest bdd将某些内容写入标准输出。这是我的stdout.feature文件: 下面是相应的测试_stdout.py: 但是,在运行pytest-v时,我遇到了一个奇怪的断言错误: 似乎test\u stdout\u capture已经执行了test\u writed\u stdout,其中stdout的内容丢失,因为当我更改断言时(即assert out==“再见”),除此之外还有另一个断言错误 这可能是什么原因造成的 Feature: test writing to s
stdout.feature
文件:
下面是相应的测试_stdout.py:
但是,在运行pytest-v
时,我遇到了一个奇怪的断言错误:
似乎test\u stdout\u capture
已经执行了test\u writed\u stdout
,其中stdout的内容丢失,因为当我更改断言时(即assert out==“再见”
),除此之外还有另一个断言错误
这可能是什么原因造成的
Feature: test writing to stdout
We are testing stdout capturing
Scenario: Trying to capture stdout
Given we have written to stdout
Then the result can be captured via capsys
from pytest_bdd import scenario, given, then
@scenario('stdout.feature', 'Trying to capture stdout')
def test_stdout_capture(capsys)::
pass
@given('we have written to stdout')
def test_stdout_write(capsys):
print('Hello')
@then('the result can be captured via capsys')
def test_written_to_stdout(capsys):
out, err = capsys.readouterr()
assert out == 'Hello\n'
...
collected 2 items
test_stdout.py::test_stdout_capture PASSED
test_stdout.py::test_written_to_stdout FAILED
...
> assert out == 'Hello\n'
E assert '' == 'Hello\n'
E + Hello
test_stdout.py:16: AssertionError