pytest在调试模式下运行时会通过,但否则会失败
以下是我执行的pytest代码来测试添加连接命令。
def test_cli_connection_add(self, cmd, expected_output, expected_conn):
runner = CliRunner()
result = runner.invoke(connections, cmd)
assert result.output.strip() == expected_output
它的问题可能会说出预期的输出应该具有新线。
> assert result.output.strip() == expected_output
E AssertionError: assert ('Successfully added `conn_id`=new4 : '\n 'hive_metastore://airflow:******@host:9083/airflow') == ('Successfully added `conn_id`=new4 : \n'\n 'hive_metastore://airflow:******@host:9083/airflow')
E + Successfully added `conn_id`=new4 : hive_metastore://airflow:******@host:9083/airflow
E - Successfully added `conn_id`=new4 :
E - hive_metastore://airflow:******@host:9083/airflow
tests/cli/commands/test_connection.py:558: AssertionError
为了进一步调试此问题,我在代码中添加了set_trace:
def test_cli_connection_add(self, cmd, expected_output, expected_conn):
pytest.set_trace()
runner = CliRunner()
result = runner.invoke(connections, cmd)
assert result.output.strip() == expected_output
当我通过debugger执行代码时,主张通过。谁能帮我为什么这样做?
Following is the pytest code that I execute to test the add connection command.
def test_cli_connection_add(self, cmd, expected_output, expected_conn):
runner = CliRunner()
result = runner.invoke(connections, cmd)
assert result.output.strip() == expected_output
It fails with issue that tells the expected output should have newline.
> assert result.output.strip() == expected_output
E AssertionError: assert ('Successfully added `conn_id`=new4 : '\n 'hive_metastore://airflow:******@host:9083/airflow') == ('Successfully added `conn_id`=new4 : \n'\n 'hive_metastore://airflow:******@host:9083/airflow')
E + Successfully added `conn_id`=new4 : hive_metastore://airflow:******@host:9083/airflow
E - Successfully added `conn_id`=new4 :
E - hive_metastore://airflow:******@host:9083/airflow
tests/cli/commands/test_connection.py:558: AssertionError
To debug this issue further I added set_trace in the code:
def test_cli_connection_add(self, cmd, expected_output, expected_conn):
pytest.set_trace()
runner = CliRunner()
result = runner.invoke(connections, cmd)
assert result.output.strip() == expected_output
When I execute the code via debugger, the assertion pass. Can anyone help me why this works this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论