Skip to content

Commit

Permalink
Merge branch 'master' into pr-135
Browse files Browse the repository at this point in the history
  • Loading branch information
wolever committed Mar 2, 2023
2 parents 0499124 + dceaf6f commit 6bba7bf
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 50 deletions.
28 changes: 24 additions & 4 deletions parameterized/parameterized.py
Expand Up @@ -307,7 +307,7 @@ def set_test_runner(name):
def detect_runner():
""" Guess which test runner we're using by traversing the stack and looking
for the first matching module. This *should* be reasonably safe, as
it's done during test disocvery where the test runner should be the
it's done during test discovery where the test runner should be the
stack frame immediately outside. """
if _test_runner_override is not None:
return _test_runner_override
Expand All @@ -330,6 +330,7 @@ def detect_runner():
return _test_runner_guess



class parameterized(object):
""" Parameterize a test case::
Expand Down Expand Up @@ -470,12 +471,29 @@ def check_input_values(cls, input_values):

@classmethod
def expand(cls, input, name_func=None, doc_func=None, skip_on_empty=False,
**legacy):
namespace=None, **legacy):
""" A "brute force" method of parameterizing test cases. Creates new
test cases and injects them into the namespace that the wrapped
function is being defined in. Useful for parameterizing tests in
subclasses of 'UnitTest', where Nose test generators don't work.
:param input: An iterable of values to pass to the test function.
:param name_func: A function that takes a single argument (the
value from the input iterable) and returns a string to use as
the name of the test case. If not provided, the name of the
test case will be the name of the test function with the
parameter value appended.
:param doc_func: A function that takes a single argument (the
value from the input iterable) and returns a string to use as
the docstring of the test case. If not provided, the docstring
of the test case will be the docstring of the test function.
:param skip_on_empty: If True, the test will be skipped if the
input iterable is empty. If False, a ValueError will be raised
if the input iterable is empty.
:param namespace: The namespace (dict-like) to inject the test cases
into. If not provided, the namespace of the test function will
be used.
>>> @parameterized.expand([("foo", 1, 2)])
... def test_add1(name, input, expected):
... actual = add1(input)
Expand All @@ -502,7 +520,9 @@ def expand(cls, input, name_func=None, doc_func=None, skip_on_empty=False,
name_func = name_func or default_name_func

def parameterized_expand_wrapper(f, instance=None):
frame_locals = inspect.currentframe().f_back.f_locals
frame_locals = namespace
if frame_locals is None:
frame_locals = inspect.currentframe().f_back.f_locals

parameters = cls.input_as_callable(input)()

Expand Down Expand Up @@ -592,7 +612,7 @@ class TestUserAccessLevel(TestCase):
)

class_name_func = class_name_func or default_class_name_func

if classname_func:
warnings.warn(
"classname_func= is deprecated; use class_name_func= instead. "
Expand Down
8 changes: 7 additions & 1 deletion parameterized/test.py
Expand Up @@ -3,7 +3,13 @@
import inspect
import mock
from unittest import TestCase
from nose.tools import assert_equal, assert_raises
try:
from nose.tools import assert_equal, assert_raises
except ImportError:
def assert_equal(*args, **kwds):
return TestCase().assertEqual(*args, **kwds)
def assert_raises(*args, **kwds):
return TestCase().assertRaises(*args, **kwds)

from .parameterized import (
PY3, PY2, parameterized, param, parameterized_argument_value_pairs,
Expand Down
32 changes: 32 additions & 0 deletions pyproject.toml
@@ -0,0 +1,32 @@
[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"

[project]
name = "parameterized"
authors = [{name = "David Wolever", email = "david@wolever.net"}]
license = {text = "FreeBSD"}
description = "Parameterized testing with any Python test framework"
readme = "README.rst"
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: BSD License",
]
urls = {Homepage = "https://github.com/wolever/parameterized"}
dynamic = ["version"]

[project.optional-dependencies]
dev = ["jinja2"]

[tool.setuptools]
include-package-data = false

[tool.setuptools.packages]
find = {namespaces = false}

[tool.setuptools.dynamic]
version = {attr = "parameterized.__version__"}

[tool.distutils.bdist_wheel]
universal = 1
6 changes: 0 additions & 6 deletions setup.cfg

This file was deleted.

38 changes: 0 additions & 38 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist=py{27,35,36,py}-{nose,nose2,pytest2,pytest3,unit,unit2},py{37,38,39}-{nose,nose2,pytest3,unit,unit2}
envlist=py{27,35,36,py}-{nose,nose2,pytest2,pytest3,unit,unit2},py{37,38,39,310,311}-{nose,nose2,pytest3,unit,unit2}
[testenv]
deps=
nose
Expand Down

0 comments on commit 6bba7bf

Please sign in to comment.