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

DM-11514: Fix a race condition in tests under pytest-xdist #273

Merged
merged 11 commits into from Aug 19, 2017

Conversation

timj
Copy link
Member

@timj timj commented Aug 18, 2017

Also fix some deprecation warnings and use of AFW_DIR.

@timj timj force-pushed the tickets/DM-11514-afw-xdist branch from 78cf4c1 to 5b8d9ea Compare August 18, 2017 03:49
@timj timj requested a review from PaulPrice August 18, 2017 03:54
@timj
Copy link
Member Author

timj commented Aug 18, 2017

@PaulPrice can you take a look at this for me please? Should be fairly non-controversial.

Copy link
Contributor

@PaulPrice PaulPrice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor implementation suggestions.

@@ -109,7 +109,7 @@ def testPersistence(self):

def testExposurePersistence(self):
"""Test that the ApCorrMap is saved with an Exposure"""
filename = "testApCorrMap.fits"
filename = "testApCorrMap-exposure.fits"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using:

with lsst.utils.tests.getTempFilePath(".fits") as filename:

That gets you automatic cleanup, and is more immune to cargo culting because it chooses a name based on the test.

Ditto in testExposureRecordPersistence.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented temp files.

@@ -181,6 +181,7 @@ def testPhotometricCalib(self):
s.setDec(dec * afwGeom.degrees)
s.set(self.table.getPsfFluxKey(), psfMags[band])

ifd.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth using the context manager? This is exactly what it's for.

with open(os.path.join(afwdataDir, "CFHT", "D2", "sdss.dat"), "r") as ifd:
    allLines = ifd.readlines()
....
for line in allLines:

Ditto below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to do that. The little Robert voice in my head was wondering if the big indenting diff was worth it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He's in my head too, which is why it was just a suggestion.
I slightly lean towards using the context manager, but it's up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made that change.

pytest can result in tests from the same class running in parallel,
leading to a race where one test writes the file and the other
test removes it before it can be read. The simplest solution
is to use distinct file names for each of the tests.
The latter is deprecated in python3
The latter is deprecated in python3
Failing to do this results in a resource warning.
This fixes a resource warning.
@timj timj force-pushed the tickets/DM-11514-afw-xdist branch from 785f983 to 1108928 Compare August 18, 2017 23:50
Without a third argument the line number reported by the
deprecation warnings is the line number of the warning itself.
This is not useful to a developer trying to determine which
method was deprecated. This changes the situation so that
the caller line number is reported by setting stacklevel=2.
@timj timj force-pushed the tickets/DM-11514-afw-xdist branch from 1108928 to 1e68ab8 Compare August 19, 2017 02:39
@timj timj merged commit 1e68ab8 into master Aug 19, 2017
@ktlim ktlim deleted the tickets/DM-11514-afw-xdist branch August 25, 2018 06:44
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

Successfully merging this pull request may close these issues.

None yet

2 participants