From a62eb978ecb2a3cf9cb206524605a8981945964a Mon Sep 17 00:00:00 2001 From: Terrence Wong Date: Sat, 29 Jun 2019 15:13:30 -0400 Subject: [PATCH] Fixes #1. Have tests inspect an exception's e.value instead of just the exception. pytest 5.0.0 no longer displays the custom text with str(e) --- stingray/pulse/tests/test_search.py | 6 +++--- stingray/tests/test_gti.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stingray/pulse/tests/test_search.py b/stingray/pulse/tests/test_search.py index 48bbb6f53..65c67ed5c 100644 --- a/stingray/pulse/tests/test_search.py +++ b/stingray/pulse/tests/test_search.py @@ -44,7 +44,7 @@ def test_phaseogram_bad_weights(self): phaseogr, phases, times, additional_info = \ phaseogram(self.event_times, self.pulse_frequency, weights=[0, 2]) - assert 'must match' in str(excinfo) + assert 'must match' in str(excinfo.value) def test_phaseogram_weights(self): phaseogr, phases, times, additional_info = \ @@ -169,7 +169,7 @@ def test_epoch_folding_search_expocorr_fails(self): with pytest.raises(ValueError) as excinfo: freq, stat = epoch_folding_search(self.event_times, frequencies, nbin=23, expocorr=True) - assert 'To calculate exposure correction' in str(excinfo) + assert 'To calculate exposure correction' in str(excinfo.value) def test_epoch_folding_search_expocorr(self): """Test pulse phase calculation, frequency only.""" @@ -288,7 +288,7 @@ def test_z_n_search_expocorr_fails(self): with pytest.raises(ValueError) as excinfo: freq, stat = z_n_search(self.event_times, frequencies, nharm=1, nbin=35, expocorr=True) - assert 'To calculate exposure correction' in str(excinfo) + assert 'To calculate exposure correction' in str(excinfo.value) def test_z_n_search_weights(self): """Test pulse phase calculation, frequency only.""" diff --git a/stingray/tests/test_gti.py b/stingray/tests/test_gti.py index e1f553806..74951a947 100644 --- a/stingray/tests/test_gti.py +++ b/stingray/tests/test_gti.py @@ -64,14 +64,14 @@ def test_gti_mask_fails_empty_time(self): gti = np.array([[0, 2.1], [3.9, 5]]) with pytest.raises(ValueError) as excinfo: create_gti_mask(arr, gti, return_new_gtis=True) - assert 'empty time array' in str(excinfo) + assert 'empty time array' in str(excinfo.value) def test_gti_mask_fails_empty_gti(self): arr = np.array([0, 1, 2, 3, 4, 5, 6]) gti = np.array([]) with pytest.raises(ValueError) as excinfo: create_gti_mask(arr, gti, return_new_gtis=True) - assert 'empty GTI array' in str(excinfo) + assert 'empty GTI array' in str(excinfo.value) def test_gti_mask_complete(self): arr = np.array([0, 1, 2, 3, 4, 5, 6]) @@ -241,5 +241,5 @@ def test_check_gtis_values(self): def test_check_gti_fails_empty(self): with pytest.raises(ValueError) as excinfo: check_gtis([]) - assert 'Empty' in str(excinfo) + assert 'Empty' in str(excinfo.value)