断言Pytest的两个数据帧不相等

时间:2018-08-27 13:45:45

标签: dataframe try-catch pytest assert

我看着另一个人的问题,我试图以此为基础提出更多问题,我试图弄清为什么这不起作用

 **@pytest.mark.parametrize("test_input_1, expected_outcome",
   [
       (diag_config["clinical_input"]["code_tbl"],
        init_cohorts.get_clinical_code(diag_config["clinical_input"]["code_tbl"]))

   ])  def test_get_clinical_code_fail(test_input_1, expected_outcome):
try:
    result = init_cohorts.get_clinical_code(test_input_1)
    expected_outcome = init_cohorts.get_clinical_code(diag_config["clinical_input"]["prov_tbl"])
    pd.testing.assert_frame_equal(result.toPandas(), expected_outcome.toPandas())
except AssertionError:
    # frames are not equal
    pass
else:
    # frames are equal
    raise AssertionError**

我以此为依据的是

def assert_frame_not_equal(*args, **kwargs):
try:
    assert_frame_equal(*args, **kwargs)
except AssertionError:
    # frames are not equal
    pass
else:
    # frames are equal
    raise AssertionError

即使我应该遇到尝试捕获应该期望的断言错误,我也遇到了关键错误。

0 个答案:

没有答案