Tests not being picked up

Hi all, new Django contributor here.

I’m trying to add some tests to the Django test suite in advance of writing a patch, and it seems that the test suite just doesn’t pick up my new test if it’s not written correctly. So this works as expected:

class SomeTestCase(TestCase):
    def test_something(self):
        raise Exception("My exception")

I run the test and get an exception. However, if I try to add a decorator used elsewhere in the test suite to the test:

class SomeTestCase(TestCase):
    @override_settings(MIDDLEWARE=[])
    def test_something(self):
        raise Exception("My exception")

The test never even gets picked up and the exception isn’t thrown. This is quite annoying as I’m not sure why the test isn’t getting picked up, and therefore aren’t sure how to fix it.

Am I missing something here? Is there some way to make it show why the test wasn’t picked up?

Note: I’ve tried running with the --v=3 flag, which shows that the application my test is in being loaded, but doesn’t show anything I would consider useful in terms of why it might be skipping my test.

Partial solution found; the error here was that I wasn’t importing override_settings.

However, the lack of useful error or warning made this whole process significantly harder than it needed to. So my original question remains of is there a way to get some sort of logging to explain why a test is being skipped / why Django considers it broken?

Oh, that is interesting. I wonder if the specific kind of error that not having imported override_settings throws makes this more difficult for us to detect (much like how ImportError is one of the hardest errors for us to tease apart when, say, loading URLs - is it that urls.py isn’t there, or that three imports deep there’s some uninstalled dependency?)

I’d definitely be in favour of improving our detection here, so if you are up for figuring out the circumstances this happens in and making the test suite better at warning about it, have at it. That may also uncover the reason this is currently suppressed, but I can’t think of a sensible reason off the top of my head.

This seems like it could prove to be an educational rabbit hole to follow, though I’m slightly pressed for time at the moment, especially given I’m currently working on a separate ticket.

Having said that I’ll make a note to create a bug ticket for it first thing in the morning and I’ll see about circling back to actually pick it up (assuming it gets approved as a valid bug) when I have the time for it :slightly_smiling_face: