@@ -461,6 +461,51 @@ def revert():
461461 request .addfinalizer (revert )
462462
463463
464+ @pytest .fixture (autouse = False , scope = "function" )
465+ def reset_context_environment_variable (request ):
466+ """Reset ANSYS_DPF_SERVER_CONTEXT."""
467+ from ansys .dpf .core import server_context as s_c
468+
469+ environment = os .environ
470+ key = s_c .DPF_SERVER_CONTEXT_ENV
471+ if key in environment .keys ():
472+ init_context = environment [key ]
473+ else :
474+ init_context = None
475+
476+ def revert ():
477+ if init_context :
478+ os .environ [key ] = init_context
479+
480+ request .addfinalizer (revert )
481+
482+
483+ @pytest .mark .skipif (running_docker or not conftest .SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0 ,
484+ reason = "AWP ROOT is not set with Docker" )
485+ @conftest .raises_for_servers_version_under ("6.0" )
486+ def test_context_environment_variable (reset_context_environment_variable ):
487+ from importlib import reload
488+ from ansys .dpf .core import server_context as s_c
489+
490+ key = s_c .DPF_SERVER_CONTEXT_ENV
491+
492+ # Test raise on wrong value
493+ os .environ [key ] = "PREM"
494+ with pytest .warns (UserWarning , match = "which is not recognized as an available "
495+ "DPF ServerContext type." ):
496+ reload (s_c )
497+ assert s_c .SERVER_CONTEXT == s_c .AvailableServerContexts .entry
498+
499+ # Test each possible value is correctly understood and sets SERVER_CONTEXT
500+ for context in s_c .EContextType :
501+ os .environ [key ] = context .name .upper ()
502+ reload (s_c )
503+ try :
504+ assert s_c .SERVER_CONTEXT == getattr (s_c .AvailableServerContexts , context .name )
505+ except AttributeError :
506+ continue
507+
508+
464509@pytest .mark .order (1 )
465510@pytest .mark .skipif (running_docker or not conftest .SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_5_0 ,
466511 reason = "AWP ROOT is not set with Docker" )
0 commit comments