Sep 28, 2011 2:16 pm
Tim ChaseWhile I asked this on the Django list as it happened to be with
some Django testing code, this might be a more generic Python
question so I'll ask here too.
When performing unittest tests, I have a number of methods of the
form
def test_foo(self):
data = (
(item1, result1),
... #bunch of tests for fence-post errors
)
for test, result in data:
self.assertEqual(process(test), result)
When I run my tests, I only get a tick for running one the one
test (test_foo), not the len(data) tests that were actually
performed. Is there a way for unittesting to report the number
of passed-assertions rather than the number of test-methods run?
-tkc
Sep 28, 2011 2:29 pm
Ben FinneyTim Chase <python.list@tim.thechases.com> writes:
> def test_foo(self):
> data = (
> (item1, result1),
> ... #bunch of tests for fence-post errors
> )
> for test, result in data:
> self.assertEqual(process(test), result)
> data = (
> (item1, result1),
> ... #bunch of tests for fence-post errors
> )
> for test, result in data:
> self.assertEqual(process(test), result)
The sets of data for running the same test we might call “scenarios”.
> When I run my tests, I only get a tick for running one the one test
> (test_foo), not the len(data) tests that were actually performed.
> (test_foo), not the len(data) tests that were actually performed.
Worse, if one of the scenarios causes the test to fail, the loop will
end and you won't get the results for the remaining scenarios.
> Is there a way for unittesting to report the number of
> passed-assertions rather than the number of test-methods run?
> passed-assertions rather than the number of test-methods run?
You can use the third-party ‘testscenarios’ library
<URL:http://pypi.python.org/pypi/test-scenarios> to generate test cases
at run time, one for each combination of scenarios with test cases on
the class. They will all be run and reported as distinct test cases.
There is even another library integrating this with Django
<URL:http://pypi.python.org/pypi/django-testscenarios>.
\ “Books and opinions, no matter from whom they came, if they are |
`\ in opposition to human rights, are nothing but dead letters.” |
_o__) —Ernestine Rose |
Ben Finney
`\ in opposition to human rights, are nothing but dead letters.” |
_o__) —Ernestine Rose |
Ben Finney
Sep 28, 2011 2:53 pm
Ben FinneyBen Finney <ben+python@benfinney.id.au> writes:
> You can use the third-party ‘testscenarios’ library
The URL got a bit mangled. The proper PyPI URL for that library is
<URL:http://pypi.python.org/pypi/testscenarios>.
> to generate test cases at run time, one for each combination of
> scenarios with test cases on the class. They will all be run and
> reported as distinct test cases.
>
> There is even another library integrating this with Django
> <URL:http://pypi.python.org/pypi/django-testscenarios>.
> scenarios with test cases on the class. They will all be run and
> reported as distinct test cases.
>
> There is even another library integrating this with Django
> <URL:http://pypi.python.org/pypi/django-testscenarios>.
\ “Don't worry about people stealing your ideas. If your ideas |
`\ are any good, you'll have to ram them down people's throats.” |
_o__) —Howard Aiken |
Ben Finney
`\ are any good, you'll have to ram them down people's throats.” |
_o__) —Howard Aiken |
Ben Finney
Previous Thread: Question about speed of sequential string replacement vs regex or
Next Thread: Is there any way to access attributes from an imported module?
Related Forum Topics
- Unittest - testing for filenames and filesize
- How to simulate tar filename substitution across pipedsubprocess.Popen() calls?
- Assert expressions
- Duck typing assert
- Unittest and threading
- Subclassing from unittest
- Unittest. customizing tstloaders / discover()
- Publish unittest results from test discovery
- Testing tools classification
- Re: simple web/html testing