`python setup.py test` fails because of strange working directory

FWIW using setup.py test is highly discouraged, you should invoke the test runner directly.

As for the error, I’m pretty sure some of your tests creates a temporary directory, os.chdir()s there and doesn’t chdir back to the original directory after the test completion so the subsequent tests use with that temporary directory (because chdir syscall affects the whole process).