@@ -220,7 +220,7 @@ def get_data_path(relative_path):
220220 return data_path
221221
222222
223- class _IrisTest_nometa (unittest .TestCase ):
223+ class IrisTest_nometa (unittest .TestCase ):
224224 """A subclass of unittest.TestCase which provides Iris specific testing functionality."""
225225
226226 _assertion_counts = collections .defaultdict (int )
@@ -855,6 +855,15 @@ def assertArrayShapeStats(self, result, shape, mean, std_dev, rtol=1e-6):
855855
856856
857857# An environment variable controls whether test timings are output.
858+ #
859+ # NOTE: to run tests with timing output, nosetests cannot be used.
860+ # At present, that includes not using "python setup.py test"
861+ # The typically best way is like this :
862+ # $ export IRIS_TEST_TIMINGS=1
863+ # $ python -m unittest discover -s iris.tests
864+ # and commonly adding ...
865+ # | grep "TIMING TEST" >iris_test_output.txt
866+ #
858867_PRINT_TEST_TIMINGS = bool (int (os .environ .get ('IRIS_TEST_TIMINGS' , 0 )))
859868
860869
@@ -863,7 +872,7 @@ def _method_path(meth):
863872 return '.' .join ([cls .__module__ , cls .__name__ , meth .__name__ ])
864873
865874
866- def _test_timings_function_decorator (fn ):
875+ def _testfunction_timing_decorator (fn ):
867876 # Function decorator for making a testcase print its execution time.
868877 @functools .wraps (fn )
869878 def inner (* args , ** kwargs ):
@@ -880,44 +889,43 @@ def inner(*args, **kwargs):
880889 return inner
881890
882891
883- def _test_timings_class_decorator (cls ):
892+ def iristest_timing_decorator (cls ):
884893 # Class decorator to make all "test_.." functions print execution timings.
885894 if _PRINT_TEST_TIMINGS :
886- # NOTE: 'dir' hits *all* function properties, including inherited ones.
895+ # NOTE: 'dir' scans *all* class properties, including inherited ones.
887896 attr_names = dir (cls )
888897 for attr_name in attr_names :
889898 attr = getattr (cls , attr_name )
890899 if callable (attr ) and attr_name .startswith ('test' ):
891- attr = _test_timings_function_decorator (attr )
900+ attr = _testfunction_timing_decorator (attr )
892901 setattr (cls , attr_name , attr )
893902 return cls
894903
895904
896- class TestTimingsMetaclass (type ):
905+ class _TestTimingsMetaclass (type ):
897906 # An alternative metaclass for IrisTest subclasses, which makes
898907 # them print execution timings for all the testcases.
899- # This is equivalent to applying the @_test_timings_class_decorator to
908+ # This is equivalent to applying the @iristest_timing_decorator to
900909 # every test class that inherits from IrisTest.
901910 # NOTE: however, it means you *cannot* specify a different metaclass for
902911 # your test class inheriting from IrisTest.
903912 # See below for how to solve that where needed.
904913 def __new__ (cls , clsname , base_classes , attrs ):
905914 result = type .__new__ (cls , clsname , base_classes , attrs )
906915 if _PRINT_TEST_TIMINGS :
907- result = _test_timings_class_decorator (result )
916+ result = iristest_timing_decorator (result )
908917 return result
909918
910919
911- class IrisTest (_IrisTest_nometa ):
912- # Derive the 'ordinary' IrisTest from _IrisTest_nometa , but add the
920+ class IrisTest (six . with_metaclass ( _TestTimingsMetaclass , IrisTest_nometa ) ):
921+ # Derive the 'ordinary' IrisTest from IrisTest_nometa , but add the
913922 # metaclass that enables test timings output.
914923 # This means that all subclasses also get the timing behaviour.
915924 # However, if a different metaclass is *wanted* for an IrisTest subclass,
916925 # this would cause a metaclass conflict.
917- # Instead, you can inherit from _IrisTest_nometa and apply the
918- # @_test_timings_class_decorator explicitly to your new testclass.
919- if _PRINT_TEST_TIMINGS :
920- __metaclass__ = TestTimingsMetaclass
926+ # Instead, you can inherit from IrisTest_nometa and apply the
927+ # @iristest_timing_decorator explicitly to your new testclass.
928+ pass
921929
922930
923931get_result_path = IrisTest .get_result_path
@@ -950,7 +958,7 @@ class GraphicsTest(GraphicsTestMixin, IrisTest):
950958 pass
951959
952960
953- class GraphicsTest_nometa (GraphicsTestMixin , _IrisTest_nometa ):
961+ class GraphicsTest_nometa (GraphicsTestMixin , IrisTest_nometa ):
954962 # Graphicstest without the metaclass providing test timings.
955963 pass
956964
0 commit comments