[TIP] getting access to the discovered test list
Kumar McMillan
kumar.mcmillan at gmail.com
Wed Feb 28 17:10:11 PST 2007
On 2/28/07, bear <bear42 at gmail.com> wrote:
> What we are doing is giving the developer the normal "run all unit tests"
> option which runs them all using the same python instance that was used to
> start nose. But a request was made to also be able to gather the list of
> tests and then start each test in its own python - that way any errant code
> won't pollute the environment for downstream tests.
>
> So what I have done is run the loader code to build a list of TestCase
> instances and then cycle thru that list calling "python run_test <insert
> name of test here>"
you could *maybe* write a nose plugin that would do this but if I were
you I'd steer clear of this kind of behavior. You are going to see a
serious slow down in your test suite if you use a python interpretter
for each test and what you have is really just a symptom of incorrect
setup/teardown state. Here are some alternatives you can try:
- Write unit tests for your testing tools themselves. Specifically,
test that they are tearing down your application data correctly. I
find that doctests are the easiest way to go for that.
- Run tests using the --stop option in nose so that you can focus on
the root cause of the error and not the chain reaction of breakage
that occurs afterwards
- Focus more on your teardown code. Clear caches, delete registries,
remove the entire database, get aggressive with it.
What you're experiencing is a common problem and one of the big
challenges in writing a test suite. But you are in a good position to
deal with it because you've already seen one bug in your test suite so
you can prepare for similar ones.
More information about the testing-in-python
mailing list