Skip to content

Instantly share code, notes, and snippets.

@danielholmstrom
Created April 8, 2013 12:55
Show Gist options
  • Save danielholmstrom/5336594 to your computer and use it in GitHub Desktop.
Save danielholmstrom/5336594 to your computer and use it in GitHub Desktop.
Nose plugin for excluding files based on python version and filename
from nose.plugins import Plugin
class PyVersion(Plugin):
"""Nose plugin that excludes files based on python version and file name
If a filename has the format NAME.pyVERSION.py and VERSION doesn't match
[major][minor][micro], [major][minor] or [major] the file will be excluded
from tests.
Example of filenames::
file.py3.py
file.py33.py
file.py330.py
file.py2.py
file.py27.py
file.py273.py
"""
name = 'pyversion'
def wantFile(self, file):
import sys
import re
version = [sys.version_info.major, sys.version_info.minor,
sys.version_info.micro]
if (re.match(r'^.+\.py\d+\.py$', file) and
not re.match(r'^.+\.py{0}{1}?{2}?\.py$'.format(*version), file)):
return False
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment