Changeset - cf8c3cf122a0
[Not reviewed]
default
1 1 1
Marc Abramowitz - 11 years ago 2015-04-15 23:58:12
marc@marc-abramowitz.com
tests: Make `parameterized` stuff work with both pytest and nose

- Use `nose.tools.nottest` if `nose` is available
- Use `pytest.mark.skipIf` if `pytest` is available
- Rename from `nose_parametrized` to `parameterized` since it's no longer
nose-specific
2 files changed with 20 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/__init__.py
Show inline comments
 
@@ -52,13 +52,13 @@ from routes.util import URLGenerator
 
from webtest import TestApp
 
from nose.plugins.skip import SkipTest
 

	
 
from kallithea.lib.compat import unittest
 
from kallithea import is_windows
 
from kallithea.model.db import User
 
from kallithea.tests.nose_parametrized import parameterized
 
from kallithea.tests.parameterized import parameterized
 
from kallithea.lib.utils2 import safe_str
 

	
 

	
 
os.environ['TZ'] = 'UTC'
 
if not is_windows:
 
    time.tzset()
kallithea/tests/parameterized.py
Show inline comments
 
file renamed from kallithea/tests/nose_parametrized.py to kallithea/tests/parameterized.py
 
@@ -2,16 +2,33 @@ import re
 
import new
 
import inspect
 
import logging
 
import logging.handlers
 
from functools import wraps
 

	
 
from nose.tools import nottest
 
from unittest import TestCase
 

	
 

	
 
def skip_test(func):
 
    try:
 
        from nose.tools import nottest
 
    except ImportError:
 
        pass
 
    else:
 
        func = nottest(func)
 

	
 
    try:
 
        import pytest
 
    except ImportError:
 
        pass
 
    else:
 
        func = pytest.mark.skipIf(True, func)
 

	
 
    return func
 

	
 

	
 
def _terrible_magic_get_defining_classes():
 
    """ Returns the set of parent classes of the class currently being defined.
 
        Will likely only work if called from the ``parameterized`` decorator.
 
        This function is entirely @brandon_rhodes's fault, as he suggested
 
        the implementation: http://stackoverflow.com/a/8793684/71522
 
        """
 
@@ -122,13 +139,13 @@ def parameterized_expand(input):
 
            name_suffix = "_%s" % (num,)
 
            if len(args) > 0 and isinstance(args[0], basestring):
 
                name_suffix += "_" + to_safe_name(args[0])
 
            name = base_name + name_suffix
 
            new_func = parameterized_expand_helper(name, f, args)
 
            frame_locals[name] = new_func
 
        return nottest(f)
 
        return skip_test(f)
 
    return parameterized_expand_wrapper
 

	
 
parameterized.expand = parameterized_expand
 

	
 

	
 
def assert_contains(haystack, needle):
0 comments (0 inline, 0 general)