1

I have a set of tests implemented with unittest, which are run automatically. I would like to run them at most once an hour and I have a method checking this condition, and returns True (if it's ok to run them) or False (if should exit tests).

How can I integrate this with unittest such that setUpClass or setUp methods exit (and do not fail) if the check function returns False?

PS: I am using python 2.6, so I can't use these

2
  • What's the start trigger? if you don't start them in the first place this problem never arises. Commented Sep 28, 2012 at 13:02
  • They are started on deploy, and I can't modify this automatic mechanism. The best solution in this situation would be to check the last time they actually run and see if it's more or less than an hour. This is not the purpose of unittest lib and they don't really provide support for this, but I am sure there's a trick for this. Commented Sep 28, 2012 at 13:07

2 Answers 2

2
  1. As Alex mentioned, you should just remember the last tests run date and either run the tests or don't from the deploy script, not from unittest.

  2. If you need modern unittest class on python 2.6 you can do "pip install unittest2".

  3. It is possible to do something like this via your own decorator that would wrap each testcase inside function that would either run them or skip on some condition, but that wouldn't be good solution for you.

Sign up to request clarification or add additional context in comments.

Comments

1

unittest in 2.6 doesn't support skipping tests (the functionality was added in 2.7: http://docs.python.org/library/unittest.html?highlight=unittest#skipping-tests-and-expected-failures), but you can use unittest2 which is a backport of the 2.7 features to earlier versions.

You'll have to invoke the tests using the unit2 wrapper script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.