Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inspect
- import unittest
- def is_called_by_nose():
- stack = inspect.stack()
- return any(x[0].f_globals['__name__'].startswith('nose.') for x in stack)
- class TestFoo(unittest.TestCase):
- def test_foo(self):
- self.assertTrue(is_called_by_nose())
- $ python -m nose test_caller
- .
- ----------------------------------------------------------------------
- Ran 1 test in 0.009s
- OK
- $ nosetests test_caller
- .
- ----------------------------------------------------------------------
- Ran 1 test in 0.009s
- OK
- $ python -m unittest test_caller
- F
- ======================================================================
- FAIL: test_foo (test_caller.TestFoo)
- ----------------------------------------------------------------------
- Traceback (most recent call last):
- File "test_caller.py", line 14, in test_foo
- self.assertTrue(is_called_by_nose())
- AssertionError: False is not true
- ----------------------------------------------------------------------
- Ran 1 test in 0.004s
- FAILED (failures=1)
Add Comment
Please, Sign In to add comment