Created
March 28, 2013 11:00
-
-
Save jsok/5262358 to your computer and use it in GitHub Desktop.
Python unittest decorator to skip tests is Alembic script revision criteria is not met.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import skipUnless | |
from alembic.config import Config | |
from alembic.script import ScriptDirectory | |
""" | |
Usage: | |
@minimum_revision_satisfied("5aa2dfb6e6a8") | |
def test_database_function(self): | |
pass | |
""" | |
def minimum_revision_satisfied(revision): | |
def is_satisfied(revision): | |
config = Config("alembic.ini") | |
script = ScriptDirectory.from_config(config) | |
head = script.get_current_head() | |
for script in script.iterate_revisions(head, None): | |
if script.revision == revision: | |
return True | |
return False | |
return skipUnless(is_satisfied(revision), "Minimum revision {0} not satisfied".format(revision)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment