Possible flakiness fix for test_dynamic_dependencies

test_dynamic_dependencies has been flaky lately, see #571. I can't reproduce it
locally, so I assume it has something to do with Travis running things more in
parallel than I do. test_dynamic_dependencies uses mktemp, which according to
the tempfile documentation should not be used and causes race conditions in
which another program may get access to the temp file first. Replacing this with
mkdtemp should fix the issue while also clarifying that a temporary directory is
wanted and not a temporary file. I haven't been able to verify that this will
fix the flakiness, but it should probably be done anyway. I also added cleanup.
An alternative solution would be importing `unittest2` on Python 2.6:

```py
try:
    import unittest2 as unittest
except ImportError:
    import unittest
```