diff --git a/GaudiKernel/CMakeLists.txt b/GaudiKernel/CMakeLists.txt index b347d855059152f0d99da010d29dbf29f9ea09e3..54addec823e2bb9aef3102b9cfd6a043a1260923 100644 --- a/GaudiKernel/CMakeLists.txt +++ b/GaudiKernel/CMakeLists.txt @@ -400,7 +400,7 @@ if(BUILD_TESTING) LABELS "Gaudi.GaudiKernel" ) - gaudi_add_pytest(tests/nose) + gaudi_add_pytest(tests/pytest) gaudi_add_module(test_CustomFactory SOURCES tests/src/custom_factory.cpp diff --git a/GaudiKernel/tests/nose/confdb/common.py b/GaudiKernel/tests/pytest/confdb/common.py similarity index 100% rename from GaudiKernel/tests/nose/confdb/common.py rename to GaudiKernel/tests/pytest/confdb/common.py diff --git a/GaudiKernel/tests/nose/confdb/test_confdb.py b/GaudiKernel/tests/pytest/confdb/test_confdb.py similarity index 100% rename from GaudiKernel/tests/nose/confdb/test_confdb.py rename to GaudiKernel/tests/pytest/confdb/test_confdb.py diff --git a/GaudiKernel/tests/nose/test_Configurables.py b/GaudiKernel/tests/pytest/test_Configurables.py similarity index 61% rename from GaudiKernel/tests/nose/test_Configurables.py rename to GaudiKernel/tests/pytest/test_Configurables.py index ec6aac5b99d44defffb54ef689aad42878a3c373..99159fc13f533f19ce564b32f289b58f8c09da82 100644 --- a/GaudiKernel/tests/nose/test_Configurables.py +++ b/GaudiKernel/tests/pytest/test_Configurables.py @@ -1,5 +1,5 @@ ##################################################################################### -# (c) Copyright 1998-2020 CERN for the benefit of the LHCb and ATLAS collaborations # +# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations # # # # This software is distributed under the terms of the Apache version 2 licence, # # copied verbatim in the file "LICENSE". # @@ -8,16 +8,19 @@ # granted to it by virtue of its status as an Intergovernmental Organization # # or submit itself to any jurisdiction. # ##################################################################################### -# Prepare dummy configurables +import pytest from GaudiKernel.Configurable import Configurable, ConfigurableAlgorithm from GaudiKernel.DataHandle import DataHandle +# Prepare dummy configurables class MyAlg(ConfigurableAlgorithm): __slots__ = { "Text": "some text", "Int": 23, "DataHandle": DataHandle("Location", "R"), + "Dict": {}, + "List": [], } def getDlls(self): @@ -27,7 +30,10 @@ class MyAlg(ConfigurableAlgorithm): return "MyAlg" -def _clean_confs(): +@pytest.fixture(autouse=True) +def clean_confs(): + """ensure that all tests start from a clean configuration""" + MyAlg.configurables.clear() Configurable.allConfigurables.clear() @@ -41,10 +47,14 @@ def test_correct(): a.Int = 42 a.Text = "value" a.DataHandle = "/Event/X" + a.Dict = {"a": 1} + a.List = [1, 2] assert a.getValuedProperties() == { "Int": 42, "Text": "value", "DataHandle": DataHandle("/Event/X", "R"), + "Dict": {"a": 1}, + "List": [1, 2], } @@ -56,51 +66,34 @@ def test_str_from_datahandle(): def test_invalid_value(): a = MyAlg() - try: + + with pytest.raises(ValueError): a.Int = "value" - assert False, "exception expected" - except AssertionError: - raise - except ValueError: - pass - except Exception as x: - assert False, "ValueError exception expected, got %s" % type(x).__name__ - - try: + + with pytest.raises(ValueError): a.Text = [123] - assert False, "exception expected" - except AssertionError: - raise - except ValueError: - pass - except Exception as x: - assert False, "ValueError exception expected, got %s" % type(x).__name__ - - try: + + with pytest.raises(ValueError): a.DataHandle = [123] - assert False, "exception expected" - except AssertionError: - raise - except ValueError: - pass - except Exception as x: - assert False, "ValueError exception expected, got %s" % type(x).__name__ + + with pytest.raises(ValueError): + a.Dict = [] + + with pytest.raises(ValueError): + a.List = {} def test_invalid_key(): a = MyAlg() - try: + + with pytest.raises(AttributeError): a.Dummy = "abc" - assert False, "exception expected" - except AssertionError: - raise - except AttributeError: - pass - except Exception as x: - assert False, "AttributeError exception expected, got %s" % type(x).__name__ - - -# ensure that all tests start from clean configuration -for _f in dir(): - if _f.startswith("test"): - setattr(locals()[_f], "setup", _clean_confs) + + +def test_collection_defaults(): + a = MyAlg() + assert a.Dict == {} + assert a.List == [] + + a.List += [1] + assert a.List == [1] diff --git a/GaudiKernel/tests/nose/test_ControlFlow.py b/GaudiKernel/tests/pytest/test_ControlFlow.py similarity index 100% rename from GaudiKernel/tests/nose/test_ControlFlow.py rename to GaudiKernel/tests/pytest/test_ControlFlow.py diff --git a/GaudiKernel/tests/nose/test_DataHandle.py b/GaudiKernel/tests/pytest/test_DataHandle.py similarity index 100% rename from GaudiKernel/tests/nose/test_DataHandle.py rename to GaudiKernel/tests/pytest/test_DataHandle.py diff --git a/GaudiKernel/tests/nose/test_instructionsetLevel.py b/GaudiKernel/tests/pytest/test_instructionsetLevel.py similarity index 88% rename from GaudiKernel/tests/nose/test_instructionsetLevel.py rename to GaudiKernel/tests/pytest/test_instructionsetLevel.py index 21f1736ab48383c776391aa3821779c4ff0db0dc..e9ce33c734a7fba6cac6d2df04e7804ee132aba2 100644 --- a/GaudiKernel/tests/nose/test_instructionsetLevel.py +++ b/GaudiKernel/tests/pytest/test_instructionsetLevel.py @@ -11,16 +11,14 @@ from platform import processor from subprocess import PIPE, Popen -from nose import SkipTest +import pytest +@pytest.mark.skipif( + processor() != "x86_64", + reason=f"platform {processor()} not supported (instructionsetLevel only works on x86_64)", +) def test(): - if processor() != "x86_64": - raise SkipTest( - "platform {} not supported (instructionsetLevel only works on x86_64".format( - processor() - ) - ) out = Popen(["instructionsetLevel", "all"], stdout=PIPE).communicate()[0] out = out.decode("utf-8") known_flags = set(l.strip() for l in out.splitlines())