From ea33cd8986036e5f9b4a237cb46e0b93e3e71ac3 Mon Sep 17 00:00:00 2001 From: jay Date: Tue, 2 Jun 2020 20:11:24 -0500 Subject: [PATCH 1/2] swap xfail for pytest.raises --- tests/test_deltaRCM_driver.py | 10 +++++----- tests/test_yaml_parsing.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_deltaRCM_driver.py b/tests/test_deltaRCM_driver.py index ea7c2408..05cba5f4 100644 --- a/tests/test_deltaRCM_driver.py +++ b/tests/test_deltaRCM_driver.py @@ -24,7 +24,7 @@ def test_init(): def test_update(): - + delta.update() assert delta._time == 1.0 assert delta._is_finalized == False @@ -35,14 +35,14 @@ def test_finalize(): assert delta._is_finalized == True -@pytest.mark.xfail(raises=RuntimeError, strict=True) def test_multifinalization_error(): err_delta = pyDeltaRCM(input_file=os.path.join(os.getcwd(), 'tests', 'test.yaml')) err_delta.update() # test will Fail if any assertion is wrong - assert err_delta._time == 1.0 + assert err_delta._time == 1.0 assert err_delta._is_finalized == False err_delta.finalize() assert err_delta._is_finalized == True - # next line should throw RuntimeError and test will xFail - err_delta.update() + # next line should throw RuntimeError + with pytest.raises(RuntimeError): + err_delta.update() diff --git a/tests/test_yaml_parsing.py b/tests/test_yaml_parsing.py index 0703ec29..f0f7907e 100644 --- a/tests/test_yaml_parsing.py +++ b/tests/test_yaml_parsing.py @@ -34,9 +34,9 @@ def test_override_from_testfile(): assert delta.Length == 10 -@pytest.mark.xfail(raises=FileNotFoundError, strict=True) def test_error_if_no_file_found(): - delta = pyDeltaRCM(input_file='./nonexisting_file.yaml') + with pytest.raises(FileNotFoundError): + delta = pyDeltaRCM(input_file='./nonexisting_file.yaml') def test_override_single_default(tmp_path): @@ -59,22 +59,22 @@ def test_override_two_defaults(tmp_path): assert delta.Np_sed == 2 -@pytest.mark.xfail(raises=TypeError, strict=True) def test_override_bad_type_float_string(tmp_path): file_name = 'user_parameters.yaml' p, f = create_temporary_file(tmp_path, file_name) write_parameter_to_file(f, 'S0', 'a string?!') f.close() - delta = pyDeltaRCM(input_file=p) + with pytest.raises(TypeError): + delta = pyDeltaRCM(input_file=p) -@pytest.mark.xfail(raises=TypeError, strict=True) def test_override_bad_type_int_float(tmp_path): file_name = 'user_parameters.yaml' p, f = create_temporary_file(tmp_path, file_name) write_parameter_to_file(f, 'beta', 24.4234) f.close() - delta = pyDeltaRCM(input_file=p) + with pytest.raises(TypeError): + delta = pyDeltaRCM(input_file=p) def test_not_creating_illegal_attributes(tmp_path): From 51b4b2c5903a39b2caf35645462b12472a4d45a5 Mon Sep 17 00:00:00 2001 From: JayH Date: Wed, 3 Jun 2020 10:35:35 -0400 Subject: [PATCH 2/2] fix last xfail --- tests/test_shared_tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_shared_tools.py b/tests/test_shared_tools.py index d29d496c..301884d2 100644 --- a/tests/test_shared_tools.py +++ b/tests/test_shared_tools.py @@ -160,10 +160,11 @@ def test_custom_unravel_rectangle(): assert y == 4 -@pytest.mark.xfail(raises=IndexError, strict=True) def test_custom_unravel_exceed_error(): arr = np.arange(9).reshape((3, 3)) - x, y = shared_tools.custom_unravel(99, arr.shape) + # next line should throw IndexError + with pytest.raises(IndexError): + x, y = shared_tools.custom_unravel(99, arr.shape) def test_check_for_loops():