Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions traits/testing/nose_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,32 @@
#
# Thanks for using Enthought open source!

"Non-standard functions for the 'nose' testing framework."
""" Non-standard functions for the 'nose' testing framework

This module is deprecated, and will be removed in a future release.

.. deprecated:: 6.1.0

"""

import warnings

try:
from nose import DeprecatedTest, SkipTest
from nose.tools import make_decorator

def skip(f):
""" Decorator to indicate a test should be skipped.

.. deprecated:: 6.1.0

"""
warnings.warn(
"The traits.testing.nose_tools module and its contents "
"are deprecated",
DeprecationWarning,
stacklevel=2,
)

def g(*args, **kw):
raise SkipTest()
Expand All @@ -25,7 +42,16 @@ def g(*args, **kw):

def deprecated(f):
""" Decorator to indicate a test is deprecated.

.. deprecated:: 6.1.0

"""
warnings.warn(
"The traits.testing.nose_tools module and its contents "
"are deprecated",
DeprecationWarning,
stacklevel=2,
)

def g(*args, **kw):
raise DeprecatedTest()
Expand All @@ -36,20 +62,34 @@ def g(*args, **kw):
except ImportError:
# Define stubs in case nose isn't installed.

import warnings

def skip(f):
""" Stub replacement for marking a unit test to be skipped in the
absence of 'nose'.

.. deprecated:: 6.1.0
"""
warnings.warn(
"The traits.testing.nose_tools module and its contents "
"are deprecated",
DeprecationWarning,
stacklevel=2,
)

warnings.warn("skipping unit tests requires the package 'nose'")
return f

def deprecated(f):
""" Stub replacement for marking a unit test deprecated in the absence
of 'nose'.

.. deprecated:: 6.1.0
"""
warnings.warn(
"The traits.testing.nose_tools module and its contents "
"are deprecated",
DeprecationWarning,
stacklevel=2,
)

warnings.warn(
"skipping deprecated unit tests requires the package 'nose'"
Expand All @@ -60,6 +100,16 @@ def deprecated(f):
def performance(f):
""" Decorator to add an attribute to the test to mark it as
a performance-measuring test.

.. deprecated:: 6.1.0

"""
warnings.warn(
"The traits.testing.nose_tools module and its contents "
"are deprecated",
DeprecationWarning,
stacklevel=2,
)

f.performance = True
return f
42 changes: 42 additions & 0 deletions traits/testing/tests/test_nose_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# (C) Copyright 2005-2020 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

import unittest

from traits.testing.nose_tools import deprecated, performance, skip


class TestNoseTools(unittest.TestCase):
def test_deprecated_deprecated(self):
with self.assertWarns(DeprecationWarning) as cm:

@deprecated
def some_func():
pass

self.assertIn("test_nose_tools", cm.filename)

def test_performance_deprecated(self):
with self.assertWarns(DeprecationWarning) as cm:

@performance
def some_func():
pass

self.assertIn("test_nose_tools", cm.filename)

def test_skip_deprecated(self):
with self.assertWarns(DeprecationWarning) as cm:

@skip
def some_func():
pass

self.assertIn("test_nose_tools", cm.filename)