Updated Doc and test format
* I reformatted the last test I made and also the doc. * English is not my first language, I apologize for any inconvenience.
* I added green output results for my test results (I also found parameterized project because of green)
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 8559710..b4fc834 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,7 @@
+0.6.3 (2017-11-18)
+ * Added parameterized_class feature. Now it supports
+ parameterized for an entire test class setting new attributes
+ and values.
0.6.2 (???)
* Make sure that `setUp` and `tearDown` methods work correctly (#40)
diff --git a/README.rst b/README.rst
index 42f295e..7ffcf2d 100644
--- a/README.rst
+++ b/README.rst
@@ -36,57 +36,116 @@
def test_floor(self, name, input, expected):
assert_equal(math.floor(input), expected)
+ @parameterized.parameterized_class(('a', 'b', 'c'), [
+ (0, 5, 6),
+ (None, None, None),
+ ({}, [], [])
+ ])
+ class TestMathClass(unittest.TestCase):
+ def _assertions(self):
+ assert hasattr(self, 'a')
+ assert hasattr(self, 'b')
+ assert hasattr(self, 'c')
+
+ def test_method_a(self):
+ self._assertions()
+
+ def test_method_b(self):
+ self._assertions()
+
+
With nose (and nose2)::
$ nosetests -v test_math.py
- test_math.test_pow(2, 2, 4) ... ok
- test_math.test_pow(2, 3, 8) ... ok
- test_math.test_pow(1, 9, 1) ... ok
- test_math.test_pow(0, 9, 0) ... ok
+ test_method_a (test_math.TestMathClass_1) ... ok
+ test_method_b (test_math.TestMathClass_1) ... ok
+ test_method_a (test_math.TestMathClass_2) ... ok
+ test_method_b (test_math.TestMathClass_2) ... ok
+ test_method_a (test_math.TestMathClass_3) ... ok
+ test_method_b (test_math.TestMathClass_3) ... ok
test_floor_0_negative (test_math.TestMathUnitTest) ... ok
test_floor_1_integer (test_math.TestMathUnitTest) ... ok
test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
+ test_math.test_pow(2, 2, 4, {}) ... ok
+ test_math.test_pow(2, 3, 8, {}) ... ok
+ test_math.test_pow(1, 9, 1, {}) ... ok
+ test_math.test_pow(0, 9, 0, {}) ... ok
----------------------------------------------------------------------
- Ran 7 tests in 0.002s
+ Ran 13 tests in 0.015s
OK
As the package name suggests, nose is best supported and will be used for all
further examples.
+
With py.test (version 2.0 and above)::
$ py.test -v test_math.py
- ============================== test session starts ==============================
- platform darwin -- Python 2.7.2 -- py-1.4.30 -- pytest-2.7.1
- collected 7 items
+ ============================= test session starts ==============================
+ platform darwin -- Python 3.6.1, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
+ collecting ... collected 13 items
+ test_math.py::TestMathClass_1::test_method_a PASSED
+ test_math.py::TestMathClass_1::test_method_b PASSED
+ test_math.py::TestMathClass_2::test_method_a PASSED
+ test_math.py::TestMathClass_2::test_method_b PASSED
+ test_math.py::TestMathClass_3::test_method_a PASSED
+ test_math.py::TestMathClass_3::test_method_b PASSED
test_math.py::test_pow::[0] PASSED
test_math.py::test_pow::[1] PASSED
test_math.py::test_pow::[2] PASSED
test_math.py::test_pow::[3] PASSED
- test_math.py::TestMathUnitTest::test_floor_0_negative
- test_math.py::TestMathUnitTest::test_floor_1_integer
- test_math.py::TestMathUnitTest::test_floor_2_large_fraction
-
- =========================== 7 passed in 0.10 seconds ============================
+ test_math.py::TestMathUnitTest::test_floor_0_negative PASSED
+ test_math.py::TestMathUnitTest::test_floor_1_integer PASSED
+ test_math.py::TestMathUnitTest::test_floor_2_large_fraction PASSED
+ ==================== 13 passed, 4 warnings in 0.16 seconds =====================
With unittest (and unittest2)::
$ python -m unittest -v test_math
+ test_method_a (test_math.TestMathClass_1) ... ok
+ test_method_b (test_math.TestMathClass_1) ... ok
+ test_method_a (test_math.TestMathClass_2) ... ok
+ test_method_b (test_math.TestMathClass_2) ... ok
+ test_method_a (test_math.TestMathClass_3) ... ok
+ test_method_b (test_math.TestMathClass_3) ... ok
test_floor_0_negative (test_math.TestMathUnitTest) ... ok
test_floor_1_integer (test_math.TestMathUnitTest) ... ok
test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok
----------------------------------------------------------------------
- Ran 3 tests in 0.000s
+ Ran 9 tests in 0.001s
OK
(note: because unittest does not support test decorators, only tests created
with ``@parameterized.expand`` will be executed)
+With green::
+
+ $ green test_math.py -vvv
+ test_math
+ TestMathClass_1
+ . test_method_a
+ . test_method_b
+ TestMathClass_2
+ . test_method_a
+ . test_method_b
+ TestMathClass_3
+ . test_method_a
+ . test_method_b
+ TestMathUnitTest
+ . test_floor_0_negative
+ . test_floor_1_integer
+ . test_floor_2_large_fraction
+
+ Ran 9 tests in 0.121s
+
+ OK (passes=9)
+
+
Installation
------------
@@ -350,6 +409,46 @@
OK
+Finally ``@parameterized.parameterized_class`` works for an entire test class, the first parameter is a tuple
+of strings or a single string, this data is going to be converted as a class properties.
+The second argument is an array of tuples, each tuple must have the same length as the first parameter because
+ they correspond to the property values:
+
+.. code:: python
+ from django.test import Client, TestCase
+ from parameterized import parameterized
+
+ @parameterized.parameterized_class('version_url', ['/v1.1/', '/v1.2/'])
+ class TestAPI(TestCase):
+ def _assertions(self):
+ assert hasattr(self, 'version_url')
+
+ def test_url_a(self):
+ self.client.get(self.version_url + '/url_a'
+ self._assertions()
+
+ def test_url_b(self):
+ self.client.get(self.version_url + '/url_b'
+ self._assertions()
+
+
+ @parameterized.parameterized_class(('a', 'b', 'c'), [
+ (0, 5, 6),
+ (None, None, None),
+ ({}, [], [])
+ ])
+ class TestMathClass(unittest.TestCase):
+ def _assertions(self):
+ assert hasattr(self, 'a')
+ assert hasattr(self, 'b')
+ assert hasattr(self, 'c')
+
+ def test_method_a(self):
+ self._assertions()
+
+ def test_method_b(self):
+ self._assertions()
+
Migrating from ``nose-parameterized`` to ``parameterized``
----------------------------------------------------------
diff --git a/parameterized/test.py b/parameterized/test.py
index 811d12c..1141212 100644
--- a/parameterized/test.py
+++ b/parameterized/test.py
@@ -70,7 +70,7 @@
if not PYTEST:
- # py.test doesn't use xunit-style setup/teardown`, so these tests don't apply
+ # py.test doesn't use xunit-style setup/teardown, so these tests don't apply
class TestSetupTeardown(object):
expect("generator", [
"test_setup(setup 1)",
@@ -323,44 +323,45 @@
("x, y=9, *a, **kw", param(1, 2, 3, z=3), [("x", 1), ("y", 2), ("*a", (3,)), ("**kw", {"z": 3})]),
])
class TestParameterizedClass(TestCase):
- expect(['TestParameterizedClass_1:test_method_a()',
- 'TestParameterizedClass_1:test_method_b()',
- 'TestParameterizedClass_2:test_method_a()',
- 'TestParameterizedClass_2:test_method_b()',
- 'TestParameterizedClass_3:test_method_a()',
- 'TestParameterizedClass_3:test_method_b()',
- 'TestParameterizedClass_4:test_method_a()',
- 'TestParameterizedClass_4:test_method_b()',
- 'TestParameterizedClass_5:test_method_a()',
- 'TestParameterizedClass_5:test_method_b()',
- 'TestParameterizedClass_6:test_method_a()',
- 'TestParameterizedClass_6:test_method_b()',
- 'TestParameterizedClass_7:test_method_a()',
- 'TestParameterizedClass_7:test_method_b()',
- 'TestParameterizedClass_8:test_method_a()',
- 'TestParameterizedClass_8:test_method_b()',
- 'TestParameterizedClass_9:test_method_a()',
- 'TestParameterizedClass_9:test_method_b()',
- 'TestParameterizedClass_10:test_method_a()',
- 'TestParameterizedClass_10:test_method_b()',
- 'TestParameterizedClass_11:test_method_a()',
- 'TestParameterizedClass_11:test_method_b()',
- 'TestParameterizedClass_12:test_method_a()',
- 'TestParameterizedClass_12:test_method_b()',
- 'TestParameterizedClass_13:test_method_a()',
- 'TestParameterizedClass_13:test_method_b()',
- 'TestParameterizedClass_14:test_method_a()',
- 'TestParameterizedClass_14:test_method_b()',
- 'TestParameterizedClass_15:test_method_a()',
- 'TestParameterizedClass_15:test_method_b()',
- 'TestParameterizedClass_16:test_method_a()',
- 'TestParameterizedClass_16:test_method_b()',
- 'TestParameterizedClass_17:test_method_a()',
- 'TestParameterizedClass_17:test_method_b()',
- 'TestParameterizedClass_18:test_method_a()',
- 'TestParameterizedClass_18:test_method_b()'
+ expect([
+ 'TestParameterizedClass_1:test_method_a()',
+ 'TestParameterizedClass_1:test_method_b()',
+ 'TestParameterizedClass_2:test_method_a()',
+ 'TestParameterizedClass_2:test_method_b()',
+ 'TestParameterizedClass_3:test_method_a()',
+ 'TestParameterizedClass_3:test_method_b()',
+ 'TestParameterizedClass_4:test_method_a()',
+ 'TestParameterizedClass_4:test_method_b()',
+ 'TestParameterizedClass_5:test_method_a()',
+ 'TestParameterizedClass_5:test_method_b()',
+ 'TestParameterizedClass_6:test_method_a()',
+ 'TestParameterizedClass_6:test_method_b()',
+ 'TestParameterizedClass_7:test_method_a()',
+ 'TestParameterizedClass_7:test_method_b()',
+ 'TestParameterizedClass_8:test_method_a()',
+ 'TestParameterizedClass_8:test_method_b()',
+ 'TestParameterizedClass_9:test_method_a()',
+ 'TestParameterizedClass_9:test_method_b()',
+ 'TestParameterizedClass_10:test_method_a()',
+ 'TestParameterizedClass_10:test_method_b()',
+ 'TestParameterizedClass_11:test_method_a()',
+ 'TestParameterizedClass_11:test_method_b()',
+ 'TestParameterizedClass_12:test_method_a()',
+ 'TestParameterizedClass_12:test_method_b()',
+ 'TestParameterizedClass_13:test_method_a()',
+ 'TestParameterizedClass_13:test_method_b()',
+ 'TestParameterizedClass_14:test_method_a()',
+ 'TestParameterizedClass_14:test_method_b()',
+ 'TestParameterizedClass_15:test_method_a()',
+ 'TestParameterizedClass_15:test_method_b()',
+ 'TestParameterizedClass_16:test_method_a()',
+ 'TestParameterizedClass_16:test_method_b()',
+ 'TestParameterizedClass_17:test_method_a()',
+ 'TestParameterizedClass_17:test_method_b()',
+ 'TestParameterizedClass_18:test_method_a()',
+ 'TestParameterizedClass_18:test_method_b()'
- ])
+ ])
def _assertions(self):
assert hasattr(self, 'a')
diff --git a/setup.py b/setup.py
index 4eac2e3..396ff94 100644
--- a/setup.py
+++ b/setup.py
@@ -14,7 +14,7 @@
setup(
name="parameterized",
- version="0.6.1",
+ version="0.6.3",
url="https://github.com/wolever/parameterized",
license="FreeBSD",
author="David Wolever",