Skip to content

Commit

Permalink
Use a fixture for npz files in test_bat (#2981)
Browse files Browse the repository at this point in the history
Fixes #2979

## Work done in this PR

The file test_bat_IO.npy was created in one test and used in
another one. This leads to the second test possibly failing
when the tests are run in parallel. This commit moves creating
the file into a fixture that the two tests depends.

The new fixture also uses the tmpdir fixture to avoid the file
created during the tests to remain in the test directory.
  • Loading branch information
jbarnoud authored Oct 14, 2020
1 parent a9543ba commit 64a7c05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Fixes
Universe (PR #2893)
* ensure that unistd.h is included on macOS when compiling ENCORE's spe.c
(Issue #2934)
* Fix tests for analysis.bat that could fail when run in parallel and that
would create a test artifact (Issue #2979, PR #2981)

Enhancements
* Refactored analysis.helanal into analysis.helix_analysis
Expand Down
19 changes: 12 additions & 7 deletions testsuite/MDAnalysisTests/analysis/test_bat.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def bat(self, selected_residues):
R.run()
return R.bat

@pytest.fixture
def bat_npz(self, tmpdir, selected_residues):
filename = str(tmpdir / 'test_bat_IO.npy')
R = BAT(selected_residues)
R.run()
R.save(filename)
return filename

def test_bat_root_selection(self, selected_residues):
R = BAT(selected_residues)
assert_equal(R._root.indices, [8, 2, 1],
Expand Down Expand Up @@ -79,11 +87,8 @@ def test_bat_reconstruction(self, selected_residues, bat):
err_msg="error: Reconstructed Cartesian coordinates " + \
"don't match original")

def test_bat_IO(self, selected_residues, bat):
R = BAT(selected_residues)
R.run()
R.save('test_bat_IO.npy')
R2 = BAT(selected_residues, filename='test_bat_IO.npy')
def test_bat_IO(self, bat_npz, selected_residues, bat):
R2 = BAT(selected_residues, filename=bat_npz)
test_bat = R2.bat
assert_almost_equal(
bat,
Expand All @@ -107,8 +112,8 @@ def test_bat_disconnected_atom_group(self):
with pytest.raises(ValueError):
R = BAT(selected_residues)

def test_bat_incorrect_dims(self):
def test_bat_incorrect_dims(self, bat_npz):
u = mda.Universe(PSF, DCD)
selected_residues = u.select_atoms("resid 1-3")
with pytest.raises(ValueError):
R = BAT(selected_residues, filename='test_bat_IO.npy')
R = BAT(selected_residues, filename=bat_npz)

0 comments on commit 64a7c05

Please sign in to comment.