I'll write it up when I finally have this whipped, but we have a unit test stumper ourselves. In our Django project, the tests have always run slow. Once we got above 50 tests I finally decided to hunt for the cause. It creates a test DB from fixtures for each test case but i couldn't understand how that could possibly take several seconds per test.
Then I was coding on the train home one night and in the tube my hotspot lost connection. Then I happened to notice... with wifi off the tests ran 10x quicker. Pull out netstat.... I see http requests to akamai essentially as each test setUp() is run. It's SSL so I only see a hostname, not the full path, and they just look like this, but the hostname is dynamic:
a23-34-132-181.deploy.static.akamaitechnologies.com
I spent 30 mins reviewing our code, grepping my code and packages directories, and stepping thru in a debugger. No luck.
Is the URL class in Java special, versus just a Uri structure?. Because relying on DNS for equivalency sounds totally wrong for many cases. At least such a compare should have a special name to indicate resolution will be attempted.
The URL class in Java is special, as in especially broken. It's very old code that probably wasn't a good idea even back then, and it's never been changed for backwards compat reasons.
Use java.net.Uri, or e.g. the equivalent from Jersey or whatever your local framework/HTTP client/... brings with it.
There is a couple of other places where this fails pretty hard. If you compare to URL's on the same shared host, they will be considered equal and equality of URI's can change as the network goes up and down. I would imagine at some point (if it hasn't already) become deprecated.
Joshua Bloch used this as an example in one of the brilliant Java Puzzler video series with the net advise of don't depend on non-local state for equality.
Ned Batchelder had an interesting post recently about finding temp file creators through monkey-patching[0]. I could see a similar approach being helpful here by patching the socket module to find all call stacks.
Take a tcpdump and open it in Wireshark - you can't see the content of the requests, but the first packet will probably have an SNI header that tells you what hostname you're trying to connect to.
That's a weird one. I've got some advice about your testing methods though. Fixtures are sloooooooow. They also run before every single test method, not just once per TestCase class, unless you're using Django 1.8 (which introduced setUpTestData which is run once per class rather than once per method). You'll get some additional speed up by converting your fixtures into python.
If that was with Java, I would do something to make network terrible slow or even unresponsive and try to dump stacktrace to catch the bugger. Not sure if you can print stacktrace in Python in the middle of something.
Then I was coding on the train home one night and in the tube my hotspot lost connection. Then I happened to notice... with wifi off the tests ran 10x quicker. Pull out netstat.... I see http requests to akamai essentially as each test setUp() is run. It's SSL so I only see a hostname, not the full path, and they just look like this, but the hostname is dynamic: a23-34-132-181.deploy.static.akamaitechnologies.com
I spent 30 mins reviewing our code, grepping my code and packages directories, and stepping thru in a debugger. No luck.