1010
1111import pytest
1212
13- pytest_plugins = ['aiida.manage.tests.pytest_fixtures' ] # pylint: disable=invalid-name
13+ # Conditionally include aiida fixtures only if aiida is available
14+ try :
15+ import aiida
16+ HAVE_AIIDA = True
17+ except ImportError :
18+ HAVE_AIIDA = False
19+
20+ if HAVE_AIIDA :
21+ pytest_plugins = ['aiida.manage.tests.pytest_fixtures' ] # pylint: disable=invalid-name
22+ else :
23+ pytest_plugins = []
1424
1525
1626@pytest .fixture (scope = 'session' )
@@ -25,25 +35,27 @@ def filepath_tests():
2535
2636
2737@pytest .fixture
28- def filepath_fixtures (filepath_tests ):
29- """Return the absolute filepath to the directory containing the file `fixtures`."""
30- return os .path .join (filepath_tests , 'fixtures' )
31-
32-
33- @pytest .fixture (scope = 'function' )
3438def fixture_sandbox ():
3539 """Return a `SandboxFolder`."""
40+ if not HAVE_AIIDA :
41+ pytest .skip ("aiida not installed" )
3642 from aiida .common .folders import SandboxFolder
3743 with SandboxFolder () as folder :
3844 yield folder
3945
4046
41- @pytest .fixture
42- def fixture_localhost (aiida_localhost ):
43- """Return a localhost `Computer`."""
44- localhost = aiida_localhost
45- localhost .set_default_mpiprocs_per_machine (1 )
46- return localhost
47+ if HAVE_AIIDA :
48+ @pytest .fixture
49+ def fixture_localhost (aiida_localhost ):
50+ """Return a localhost `Computer`."""
51+ localhost = aiida_localhost
52+ localhost .set_default_mpiprocs_per_machine (1 )
53+ return localhost
54+ else :
55+ @pytest .fixture
56+ def fixture_localhost ():
57+ """Dummy fixture when aiida is not installed."""
58+ pytest .skip ("aiida not installed" )
4759
4860
4961@pytest .fixture
@@ -131,49 +143,51 @@ def _serialize_builder(builder):
131143 return _serialize_builder
132144
133145
134- @pytest .fixture (scope = 'session' , autouse = True )
135- def sssp (aiida_profile , generate_upf_data ):
136- """Create an SSSP pseudo potential family from scratch."""
137- from aiida .common .constants import elements
138- from aiida .plugins import GroupFactory
146+ if HAVE_AIIDA :
139147
140- aiida_profile .clear_profile ()
148+ @pytest .fixture (scope = 'session' , autouse = True )
149+ def sssp (aiida_profile , generate_upf_data ):
150+ """Create an SSSP pseudo potential family from scratch."""
151+ from aiida .common .constants import elements
152+ from aiida .plugins import GroupFactory
141153
142- SsspFamily = GroupFactory ( 'pseudo.family.sssp' )
154+ aiida_profile . clear_profile ( )
143155
144- cutoffs = {}
145- stringency = 'standard'
156+ SsspFamily = GroupFactory ('pseudo.family.sssp' )
146157
147- with tempfile . TemporaryDirectory () as dirpath :
148- for values in elements . values ():
158+ cutoffs = {}
159+ stringency = 'standard'
149160
150- element = values ['symbol' ]
161+ with tempfile .TemporaryDirectory () as dirpath :
162+ for values in elements .values ():
151163
152- actinides = ( 'Ac' , 'Th' , 'Pa' , 'U' , 'Np' , 'Pu' , 'Am' , 'Cm' , 'Bk' , 'Cf' , 'Es' , 'Fm' , 'Md' , 'No' , 'Lr' )
164+ element = values [ 'symbol' ]
153165
154- if element in actinides :
155- continue
166+ actinides = ('Ac' , 'Th' , 'Pa' , 'U' , 'Np' , 'Pu' , 'Am' , 'Cm' , 'Bk' , 'Cf' , 'Es' , 'Fm' , 'Md' , 'No' , 'Lr' )
156167
157- upf = generate_upf_data (element )
158- dirpath = pathlib .Path (dirpath )
159- filename = dirpath / f'{ element } .upf'
168+ if element in actinides :
169+ continue
160170
161- with open (filename , 'w+b' ) as handle :
162- with upf .open (mode = 'rb' ) as source :
163- handle .write (source .read ())
164- handle .flush ()
171+ upf = generate_upf_data (element )
172+ dirpath = pathlib .Path (dirpath )
173+ filename = dirpath / f'{ element } .upf'
165174
166- cutoffs [element ] = {
167- 'cutoff_wfc' : 30.0 ,
168- 'cutoff_rho' : 240.0 ,
169- }
175+ with open (filename , 'w+b' ) as handle :
176+ with upf .open (mode = 'rb' ) as source :
177+ handle .write (source .read ())
178+ handle .flush ()
179+
180+ cutoffs [element ] = {
181+ 'cutoff_wfc' : 30.0 ,
182+ 'cutoff_rho' : 240.0 ,
183+ }
170184
171- label = 'SSSP/1.3/PBEsol/efficiency'
172- family = SsspFamily .create_from_folder (dirpath , label )
185+ label = 'SSSP/1.3/PBEsol/efficiency'
186+ family = SsspFamily .create_from_folder (dirpath , label )
173187
174- family .set_cutoffs (cutoffs , stringency , unit = 'Ry' )
188+ family .set_cutoffs (cutoffs , stringency , unit = 'Ry' )
175189
176- return family
190+ return family
177191
178192
179193@pytest .fixture
0 commit comments