'Pytest passes when run in debug mode but fails otherwise

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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source