testing-cabal / testtools

Testtools - tasteful testing for python
https://testtools.readthedocs.io/en/latest/
Other
95 stars 88 forks source link

Check for junk in the main reactor in the tearDown of each test #287

Open adiroiban opened 4 years ago

adiroiban commented 4 years ago

This is an issue I found in txacme..

There was a test not using AsynchronousDeferredRunTest but using the main reactor and it left the reactor dirty...

Then, another test was executed with AsynchronousDeferredRunTest and the main reactor. This test was fine, but test were still failing as it was now detecting that reactor is not clean.

I think that in twistedsuppor there should be a dedicated TestCase to check for junk at tearDown for the main reactor

Also, I think that besides delayedcalls, readers and writers and threads should also be considered junk

For my projects I am using a simplified TwistedTestCase on top of stdlib TestCase and here is the reactor cleanup check that I use:

https://github.com/chevah/compat/blob/master/chevah/compat/testing/testcase.py#L310

adiroiban commented 4 years ago

Here is my fix for txacme to help detect "drity" tests.

I guess that this is a common patter in all Twisted tests and we might have something like this in testtools

https://github.com/twisted/txacme/pull/140/commits/1a49fcbb2700f9caa812b5bd95be708f185a36e2