/functional_tests/test_plugin_api.py

https://bitbucket.org/jpellerin/nose/ · Python · 45 lines · 34 code · 7 blank · 4 comment · 6 complexity · 27e30a232b1c76c8bc4033fceb1f79da MD5 · raw file

  1. """
  2. Functional tests of plugin apis -- individual plugintester runs for
  3. test plugins that implement one or more hooks for testing.
  4. """
  5. import os
  6. import sys
  7. import unittest
  8. from nose.plugins import Plugin, PluginTester
  9. support = os.path.join(os.path.dirname(__file__), 'support')
  10. class AllFail(Plugin):
  11. def prepareTestCase(self, test):
  12. self.test = test
  13. return self.fail
  14. def fail(self, result):
  15. result.startTest(self.test)
  16. try:
  17. try:
  18. assert False, "I want to fail!"
  19. except:
  20. result.addFailure(self.test, sys.exc_info())
  21. finally:
  22. result.stopTest(self.test)
  23. class TestPrepareTestCase_MakeAllFail(PluginTester, unittest.TestCase):
  24. activate = '--with-allfail'
  25. args = ['-v']
  26. plugins = [AllFail()]
  27. suitepath = os.path.join(support, 'package2')
  28. def runTest(self):
  29. print "x" * 70
  30. print str(self.output)
  31. print "x" * 70
  32. for line in self.output:
  33. if line.startswith('test_pak'):
  34. assert line.strip().endswith('FAIL'), \
  35. "Expected failure but got: %s" % line.strip()
  36. assert not str(self.output).strip().endswith('OK')
  37. if __name__ == '__main__':
  38. unittest.main()