Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python capsys损坏,使用pytest bdd时可能会对一个步骤进行两次计算?_Python_Python 3.x_Bdd_Pytest - Fatal编程技术网

Python capsys损坏,使用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

我想断言,使用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 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