Skip to content

Instantly share code, notes, and snippets.

@jsok
Created March 28, 2013 11:00
Show Gist options
  • Save jsok/5262358 to your computer and use it in GitHub Desktop.
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.
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