Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail when run on pytest 5.0.0 #1

Closed
twongCMU opened this issue Jun 29, 2019 · 3 comments
Closed

Tests fail when run on pytest 5.0.0 #1

twongCMU opened this issue Jun 29, 2019 · 3 comments

Comments

@twongCMU
Copy link
Owner

twongCMU commented Jun 29, 2019

`On Pytest 4.6.3 the test pass fine but on 5.0.0 some fail:
platform linux -- Python 3.5.2, pytest-5.0.0, py-1.8.0, pluggy-0.12.0

Running tests with Astropy version 3.2.1.
Running tests in stingray docs.

Date: 2019-06-29T13:53:19

Platform: Linux-4.4.0-150-generic-x86_64-with-Ubuntu-16.04-xenial

Executable: /usr/bin/python3

Full Python Version:
3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Numpy: 1.16.4
Scipy: 1.3.0
Matplotlib: 3.0.3
h5py: 2.9.0
Pandas: 0.24.2
astropy_helpers: 3.2.1
Using Astropy options: remote_data: none.

rootdir: /tmp/stingray-test-gaqwq6do/lib/python3.5/site-packages, inifile: setup.cfg
plugins: doctestplus-0.3.0, arraydiff-0.3, remotedata-0.3.1, openfiles-0.3.2

...

====================================================================================================== FAILURES =======================================================================================================
_________________________________________________________________________________________ TestAll.test_phaseogram_bad_weights _________________________________________________________________________________________

self = <stingray.pulse.tests.test_search.TestAll object at 0x7f73361f9400>

def test_phaseogram_bad_weights(self):
    with pytest.raises(ValueError) as excinfo:
        phaseogr, phases, times, additional_info = \
            phaseogram(self.event_times, self.pulse_frequency,
                       weights=[0, 2])

E TypeError: Can't convert 'ExceptionInfo' object to str implicitly

stingray/pulse/tests/test_search.py:47: TypeError
__________________________________________________________________________________ TestAll.test_epoch_folding_search_expocorr_fails ___________________________________________________________________________________

self = <stingray.pulse.tests.test_search.TestAll object at 0x7f732815dba8>

def test_epoch_folding_search_expocorr_fails(self):
    """Test pulse phase calculation, frequency only."""
    frequencies = np.arange(9.8, 9.99, 0.1/self.tseg)
    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)

E AssertionError: assert 'To calculate exposure correction' in ''
E + where '' = str()

stingray/pulse/tests/test_search.py:173: AssertionError
_______________________________________________________________________________________ TestAll.test_z_n_search_expocorr_fails ________________________________________________________________________________________

self = <stingray.pulse.tests.test_search.TestAll object at 0x7f73280dbfd0>

def test_z_n_search_expocorr_fails(self):
    """Test pulse phase calculation, frequency only."""
    frequencies = np.arange(9.8, 9.99, 0.1/self.tseg)
    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)

E AssertionError: assert 'To calculate exposure correction' in ''
E + where '' = str()

stingray/pulse/tests/test_search.py:292: AssertionError
_______________________________________________________________________________________ TestGTI.test_gti_mask_fails_empty_time ________________________________________________________________________________________

self = <stingray.tests.test_gti.TestGTI object at 0x7f73272bf5c0>

def test_gti_mask_fails_empty_time(self):
    arr = np.array([])
    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)

E AssertionError: assert 'empty time array' in ''
E + where '' = str()

stingray/tests/test_gti.py:67: AssertionError
________________________________________________________________________________________ TestGTI.test_gti_mask_fails_empty_gti ________________________________________________________________________________________

self = <stingray.tests.test_gti.TestGTI object at 0x7f73272c7438>

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)

E AssertionError: assert 'empty GTI array' in ''
E + where '' = str()

stingray/tests/test_gti.py:74: AssertionError
_________________________________________________________________________________________ TestGTI.test_check_gti_fails_empty __________________________________________________________________________________________

self = <stingray.tests.test_gti.TestGTI object at 0x7f73272d3710>

def test_check_gti_fails_empty(self):
    with pytest.raises(ValueError) as excinfo:
        check_gtis([])
  assert 'Empty' in str(excinfo)

E AssertionError: assert 'Empty' in ''
E + where '' = str()

stingray/tests/test_gti.py:244: AssertionError
========================================================================== 6 failed, 747 passed, 8 skipped, 7325 warnings in 221.80 seconds ===========================================================================`

@twongCMU
Copy link
Owner Author

This happens because in 5.0.0, the exception object does not include the text of the exception, just the type:

<ExceptionInfo ValueError tblen=2>

so when the test looks for a specific substring it doesn't find it. The solution is to print the the .value of the exception to get the full text. I tested this fix on pytest 5.0.0, 4.6.3, and 3.10.1.

@twongCMU
Copy link
Owner Author

twongCMU commented Jun 29, 2019

pytest 5.0.0 was released June 28, 2019.

This issue is the one that caused the tests to fail

@twongCMU
Copy link
Owner Author

This fix is affected by StingraySoftware#416 and the temporary hack listed there was used to get the tests passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant