diff --git a/nglview/tests/test_widget.py b/nglview/tests/test_widget.py index f1ef2b91..a64753ab 100644 --- a/nglview/tests/test_widget.py +++ b/nglview/tests/test_widget.py @@ -26,65 +26,24 @@ from utils import get_fn from utils import repr_dict as REPR_DICT -try: - import simpletraj - has_simpletraj = True -except ImportError: - has_simpletraj = False - -try: - import pytraj as pt - has_pytraj = True -except ImportError: - pt = None - has_pytraj = False - -try: - import mdtraj as md - has_mdtraj = True -except ImportError: - has_mdtraj = False -try: - import parmed as pmd - has_parmed = True -except ImportError: - has_parmed = False - -try: - import MDAnalysis - has_MDAnalysis = True -except ImportError: - has_MDAnalysis = False - -try: - import htmd - has_HTMD = True -except ImportError: - has_HTMD = False - -try: - import ase - has_ase = True -except ImportError: - has_ase = False - -try: - import pymatgen - has_pymatgen = True -except ImportError: - has_pymatgen = False - -try: - import Bio.PDB - has_bio = True -except ImportError: - has_bio = False - -try: - import qcelemental - has_qcelemental = True -except ImportError: - has_qcelemental = False +modules = { + 'simpletraj': 'has_simpletraj', + 'pytraj': 'has_pytraj', + 'mdtraj': 'has_mdtraj', + 'parmed': 'has_parmed', + 'MDAnalysis': 'has_MDAnalysis', + 'htmd': 'has_HTMD', + 'ase': 'has_ase', + 'pymatgen': 'has_pymatgen', + 'Bio.PDB': 'has_bio', + 'qcelemental': 'has_qcelemental' +} + +for module, var in modules.items(): + try: + globals()[var] = __import__(module) + except ImportError: + globals()[var] = False def get_mocked_traj():