Repository: PlasmaPy/PlasmaPy

Issue:
Bring back parallel testing in tox.ini
I forgot a flag in there while debugging.


Discussion:

Resolving patch:
diff --git a/plasmapy/classes/sources/openpmd_hdf5.py b/plasmapy/classes/sources/openpmd_hdf5.py
--- a/plasmapy/classes/sources/openpmd_hdf5.py
+++ b/plasmapy/classes/sources/openpmd_hdf5.py
@@ -84,6 +84,15 @@ def __init__(self, hdf5, **kwargs):
 
         self.subname = tuple(self.h5['data'])[0]
 
+    def __enter__(self):
+        return self.h5
+
+    def close(self):
+        self.h5.close()
+
+    def __exit__(self):
+        self.h5.close()
+
     def _check_valid_openpmd_version(self):
         try:
             openPMD_version = self.h5.attrs["openPMD"].decode('utf-8')


Test patch:
diff --git a/plasmapy/classes/sources/tests/test_openpmd_hdf5.py b/plasmapy/classes/sources/tests/test_openpmd_hdf5.py
--- a/plasmapy/classes/sources/tests/test_openpmd_hdf5.py
+++ b/plasmapy/classes/sources/tests/test_openpmd_hdf5.py
@@ -1,39 +1,56 @@
 from plasmapy.classes.sources import openpmd_hdf5
 from plasmapy.classes.exceptions import DataStandardError
 from plasmapy.data.test import rootdir
+import plasmapy.classes
 
 from astropy import units as u
 from typing import Union, Tuple, List
 import os
 import pytest
 
+@pytest.fixture(scope='module')
+def h5_2d(request):
+    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000255.h5"))
+    yield h5
+    h5.close()
+
+@pytest.fixture(scope='module')
+def h5_3d(request):
+    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000100.h5"))
+    yield h5
+    h5.close()
+
+@pytest.fixture(scope='module')
+def h5_theta(request):
+    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000200.h5"))
+    yield h5
+    h5.close()
 
 class TestOpenPMD2D:
     """Test 2D HDF5 dataset based on OpenPMD."""
     # Downloaded from
     # https://github.com/openPMD/openPMD-example-datasets/blob/draft/example-2d.tar.gz
     # per the Creative Commons Zero v1.0 Universal license
-    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000255.h5"))
 
-    def test_has_electric_field_with_units(self):
-        assert isinstance(self.h5.electric_field.to(u.V / u.m), u.Quantity)
+    def test_has_electric_field_with_units(self, h5_2d):
+        assert isinstance(h5_2d.electric_field.to(u.V / u.m), u.Quantity)
 
-    def test_correct_shape_electric_field(self):
-        assert self.h5.electric_field.shape == (3, 51, 201)
+    def test_correct_shape_electric_field(self, h5_2d):
+        assert h5_2d.electric_field.shape == (3, 51, 201)
 
-    def test_has_charge_density_with_units(self):
-        assert self.h5.charge_density.to(u.C / u.m**3)
+    def test_has_charge_density_with_units(self, h5_2d):
+        assert h5_2d.charge_density.to(u.C / u.m**3)
 
-    def test_correct_shape_charge_density(self):
-        assert self.h5.charge_density.shape == (51, 201)
+    def test_correct_shape_charge_density(self, h5_2d):
+        assert h5_2d.charge_density.shape == (51, 201)
 
-    def test_has_magnetic_field(self):
+    def test_has_magnetic_field(self, h5_2d):
         with pytest.raises(AttributeError):
-            self.h5.magnetic_field
+            h5_2d.magnetic_field
 
-    def test_has_electric_current(self):
+    def test_has_electric_current(self, h5_2d):
         with pytest.raises(AttributeError):
-            self.h5.electric_current
+            h5_2d.electric_current
 
 
 class TestOpenPMD3D:
@@ -41,27 +58,26 @@ class TestOpenPMD3D:
     # Downloaded from
     # https://github.com/openPMD/openPMD-example-datasets/blob/draft/example-3d.tar.gz
     # per the Creative Commons Zero v1.0 Universal license
-    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000100.h5"))
 
-    def test_has_electric_field_with_units(self):
-        assert isinstance(self.h5.electric_field.to(u.V / u.m), u.Quantity)
+    def test_has_electric_field_with_units(self, h5_3d):
+        assert isinstance(h5_3d.electric_field.to(u.V / u.m), u.Quantity)
 
-    def test_correct_shape_electric_field(self):
-        assert self.h5.electric_field.shape == (3, 26, 26, 201)
+    def test_correct_shape_electric_field(self, h5_3d):
+        assert h5_3d.electric_field.shape == (3, 26, 26, 201)
 
-    def test_has_charge_density_with_units(self):
-        assert isinstance(self.h5.charge_density.to(u.C / u.m**3), u.Quantity)
+    def test_has_charge_density_with_units(self, h5_3d):
+        assert isinstance(h5_3d.charge_density.to(u.C / u.m**3), u.Quantity)
 
-    def test_correct_shape_charge_density(self):
-        assert self.h5.charge_density.shape == (26, 26, 201)
+    def test_correct_shape_charge_density(self, h5_3d):
+        assert h5_3d.charge_density.shape == (26, 26, 201)
 
-    def test_has_magnetic_field(self):
+    def test_has_magnetic_field(self, h5_3d):
         with pytest.raises(AttributeError):
-            self.h5.magnetic_field
+            h5_3d.magnetic_field
 
-    def test_has_electric_current(self):
+    def test_has_electric_current(self, h5_3d):
         with pytest.raises(AttributeError):
-            self.h5.electric_current
+            h5_3d.electric_current
 
 
 class TestOpenPMDThetaMode:
@@ -69,31 +85,30 @@ class TestOpenPMDThetaMode:
     # Downloaded from
     # https://github.com/openPMD/openPMD-example-datasets/blob/draft/example-thetaMode.tar.gz
     # per the Creative Commons Zero v1.0 Universal license
-    h5 = openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "data00000200.h5"))
 
-    def test_has_electric_field_with_units(self):
-        assert isinstance(self.h5.electric_field.to(u.V / u.m), u.Quantity)
+    def test_has_electric_field_with_units(self, h5_theta):
+        assert isinstance(h5_theta.electric_field.to(u.V / u.m), u.Quantity)
 
-    def test_correct_shape_electric_field(self):
-        assert self.h5.electric_field.shape == (3, 3, 51, 201)
+    def test_correct_shape_electric_field(self, h5_theta):
+        assert h5_theta.electric_field.shape == (3, 3, 51, 201)
 
-    def test_has_charge_density_with_units(self):
-        assert isinstance(self.h5.charge_density.to(u.C / u.m**3), u.Quantity)
+    def test_has_charge_density_with_units(self, h5_theta):
+        assert isinstance(h5_theta.charge_density.to(u.C / u.m**3), u.Quantity)
 
-    def test_correct_shape_charge_density(self):
-        assert self.h5.charge_density.shape == (3, 51, 201)
+    def test_correct_shape_charge_density(self, h5_theta):
+        assert h5_theta.charge_density.shape == (3, 51, 201)
 
-    def test_has_magnetic_field_with_units(self):
-        assert isinstance(self.h5.magnetic_field.to(u.T), u.Quantity)
+    def test_has_magnetic_field_with_units(self, h5_theta):
+        assert isinstance(h5_theta.magnetic_field.to(u.T), u.Quantity)
 
-    def test_correct_shape_magnetic_field(self):
-        assert self.h5.magnetic_field.shape == (3, 3, 51, 201)
+    def test_correct_shape_magnetic_field(self, h5_theta):
+        assert h5_theta.magnetic_field.shape == (3, 3, 51, 201)
 
-    def test_has_electric_current_with_units(self):
-        assert isinstance(self.h5.electric_current.to(u.A * u.kg / u.m**3), u.Quantity)
+    def test_has_electric_current_with_units(self, h5_theta):
+        assert isinstance(h5_theta.electric_current.to(u.A * u.kg / u.m**3), u.Quantity)
 
-    def test_correct_shape_electric_current(self):
-        assert self.h5.electric_current.shape == (3, 3, 51, 201)
+    def test_correct_shape_electric_current(self, h5_theta):
+        assert h5_theta.electric_current.shape == (3, 3, 51, 201)
 
 
 units_test_table = [
@@ -122,3 +137,7 @@ def test_unavailable_hdf5():
 def test_non_openpmd_hdf5():
     with pytest.raises(DataStandardError):
         openpmd_hdf5.HDF5Reader(hdf5=os.path.join(rootdir, "blank.h5"))
+
+def test_HDF5Reader(h5_2d):
+    assert isinstance(h5_2d, plasmapy.classes.sources.HDF5Reader)
+    assert isinstance(h5_2d, plasmapy.classes.BasePlasma)
diff --git a/plasmapy/classes/tests/test_plasma_factory.py b/plasmapy/classes/tests/test_plasma_factory.py
--- a/plasmapy/classes/tests/test_plasma_factory.py
+++ b/plasmapy/classes/tests/test_plasma_factory.py
@@ -1,10 +1,16 @@
 import astropy.units as u
 import numpy as np
 import os
+import pytest
 
 import plasmapy.classes
 from plasmapy.data.test import rootdir
 
+@pytest.fixture(scope='module')
+def h5(request):
+    h5 = plasmapy.classes.Plasma(hdf5=os.path.join(rootdir, "data00000255.h5"))
+    yield h5
+    h5.close()
 
 class TestPlasma(object):
     def test_patters(self):
@@ -32,8 +38,3 @@ def test_PlasmaBlob(self):
                                        particle=particle)
         assert isinstance(blob, plasmapy.classes.sources.PlasmaBlob)
         assert isinstance(blob, plasmapy.classes.BasePlasma)
-
-    def test_HDF5Reader(self):
-        h5 = plasmapy.classes.Plasma(hdf5=os.path.join(rootdir, "data00000255.h5"))
-        assert isinstance(h5, plasmapy.classes.sources.HDF5Reader)
-        assert isinstance(h5, plasmapy.classes.BasePlasma)