ImportError on public repo, not on private

Howdy! I have a python package that can successfully execute tests locally. When I run it in Travis in its main Github repository (public), it fails with import errors on the test classes/modules:

ERROR: django_presskit.tests.test_views (unittest.loader.ModuleImportFailure)
ImportError: Failed to import test module: django_presskit.tests.test_views
Traceback (most recent call last):
  File "/opt/python/2.7.14/lib/python2.7/unittest/", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/opt/python/2.7.14/lib/python2.7/unittest/", line 232, in _get_module_from_name
ImportError: No module named tests.test_views

The specific build:

If I mirror this repo into a private Github repository, however, it works perfectly. Here are some things I’ve tried in the public repo:

  • Installing or not installing the package before trying to run the tests
  • Adding additional search paths in Python, per “Test Discovery Wrinkle
  • Calling via coverage or python
  • Removing a shebang in the file

I have debugging enabled on the public repo, but I wasn’t particularly sure of what to try once I SSH’d in. Running the stages manually just produced the error again.

With the exact same code and configuration (verified via a diff of the folders) succeeding in a private repo and not on a public one, there must be something different between the Travis environments between the two, right? I’m pretty stumped.

Do you have a URL to the private repo build that succeeds? If I go through the commands with my Docker image, the command fails similarly, so I am guessing that it is broken, but the private one has some critical difference that makes it go.

I couldn’t find a way to make a private build public, so I just made the repo public. Build still works:

Thanks for the information. I also confirmed that “averymd/improved-sniffle” passes when I run the commands in question, consistent with your report.

This points to the correct behavior on our system, and the issue(s) in your “FutureProofGames” repository.

I don’t know enough about Python to give you meaningful advice, but if you compare the two repositories I get a few differences that might point you to revelation.

diff -r averymd/improved-sniffle/ FutureProofGames/django_presskit/
(python2.7.14) travis@5d2e3ae6b85e:~$ diff -r averymd/improved-sniffle/ FutureProofGames/django_presskit/
Binary files averymd/improved-sniffle/django_presskit/__init__.pyc and FutureProofGames/django_presskit/django_presskit/__init__.pyc differ
Binary files averymd/improved-sniffle/django_presskit/migrations/0001_initial.pyc and FutureProofGames/django_presskit/django_presskit/migrations/0001_initial.pyc differ
Binary files averymd/improved-sniffle/django_presskit/migrations/0002_auto_20181002_1847.pyc and FutureProofGames/django_presskit/django_presskit/migrations/0002_auto_20181002_1847.pyc differ
Binary files averymd/improved-sniffle/django_presskit/migrations/0003_auto_20181002_1915.pyc and FutureProofGames/django_presskit/django_presskit/migrations/0003_auto_20181002_1915.pyc differ
Binary files averymd/improved-sniffle/django_presskit/migrations/__init__.pyc and FutureProofGames/django_presskit/django_presskit/migrations/__init__.pyc differ
Binary files averymd/improved-sniffle/django_presskit/models.pyc and FutureProofGames/django_presskit/django_presskit/models.pyc differ
Only in averymd/improved-sniffle/django_presskit/templatetags: dpk_util.pyc
Only in averymd/improved-sniffle/django_presskit/templatetags: __init__.pyc
Binary files averymd/improved-sniffle/django_presskit/urls.pyc and FutureProofGames/django_presskit/django_presskit/urls.pyc differ
Binary files averymd/improved-sniffle/django_presskit/views.pyc and FutureProofGames/django_presskit/django_presskit/views.pyc differ
diff -r averymd/improved-sniffle/.git/config FutureProofGames/django_presskit/.git/config
<       url =
>       url =
diff -r averymd/improved-sniffle/.git/HEAD FutureProofGames/django_presskit/.git/HEAD
< 9bef5dc2d5854f033b3f6b857c2579b926aa1669
> 9403e0a37d7b9f33c6cff7d5aa260d6085eed68a
Binary files averymd/improved-sniffle/.git/index and FutureProofGames/django_presskit/.git/index differ
diff -r averymd/improved-sniffle/.git/logs/HEAD FutureProofGames/django_presskit/.git/logs/HEAD
< 0000000000000000000000000000000000000000 9bef5dc2d5854f033b3f6b857c2579b926aa1669 Travis CI User  1550674866 +0000        clone: from
< 9bef5dc2d5854f033b3f6b857c2579b926aa1669 9bef5dc2d5854f033b3f6b857c2579b926aa1669 Travis CI User  1550674878 +0000        checkout: moving from feature/dpk-10 to 9bef5dc2d5854f033b3f6b857c2579b926aa1669
> 0000000000000000000000000000000000000000 b6ed1903862e819880cbc65a77cbb3c8cd2a5463 Travis CI User  1550675127 +0000        clone: from
> b6ed1903862e819880cbc65a77cbb3c8cd2a5463 9403e0a37d7b9f33c6cff7d5aa260d6085eed68a Travis CI User  1550675142 +0000        checkout: moving from feature/dpk-10 to 9403e0a37d7b9f33c6cff7d5aa260d6085eed68a
diff -r averymd/improved-sniffle/.git/logs/refs/heads/feature/dpk-10 FutureProofGames/django_presskit/.git/logs/refs/heads/feature/dpk-10
< 0000000000000000000000000000000000000000 9bef5dc2d5854f033b3f6b857c2579b926aa1669 Travis CI User  1550674866 +0000        clone: from
> 0000000000000000000000000000000000000000 b6ed1903862e819880cbc65a77cbb3c8cd2a5463 Travis CI User  1550675127 +0000        clone: from
Only in averymd/improved-sniffle/.git/objects/pack: pack-93d5aa38515913a98fc4809b039abae3ffc00286.idx
Only in averymd/improved-sniffle/.git/objects/pack: pack-93d5aa38515913a98fc4809b039abae3ffc00286.pack
Only in FutureProofGames/django_presskit/.git/objects/pack: pack-93f85228ac53089099667be00222829ac4671736.idx
Only in FutureProofGames/django_presskit/.git/objects/pack: pack-93f85228ac53089099667be00222829ac4671736.pack
diff -r averymd/improved-sniffle/.git/packed-refs FutureProofGames/django_presskit/.git/packed-refs
< 9bef5dc2d5854f033b3f6b857c2579b926aa1669 refs/remotes/origin/feature/dpk-10
> b6ed1903862e819880cbc65a77cbb3c8cd2a5463 refs/remotes/origin/feature/dpk-10
diff -r averymd/improved-sniffle/.git/refs/heads/feature/dpk-10 FutureProofGames/django_presskit/.git/refs/heads/feature/dpk-10
< 9bef5dc2d5854f033b3f6b857c2579b926aa1669
> b6ed1903862e819880cbc65a77cbb3c8cd2a5463
Only in averymd/improved-sniffle/: __init__.pyc
diff -r averymd/improved-sniffle/requirements.txt FutureProofGames/django_presskit/requirements.txt
< coverage==4.4.2
< Pillow==4.3.0
\ No newline at end of file
> Pillow==4.3.0
diff -r averymd/improved-sniffle/ FutureProofGames/django_presskit/
>     sys.path.insert(0, os.path.abspath("../"))
>     sys.path.insert(0, os.path.abspath("."))
Binary files averymd/improved-sniffle/tests/__init__.pyc and FutureProofGames/django_presskit/tests/__init__.pyc differ
Binary files averymd/improved-sniffle/tests/settings.pyc and FutureProofGames/django_presskit/tests/settings.pyc differ
Only in averymd/improved-sniffle/tests: test_dpk_util.pyc
Only in averymd/improved-sniffle/tests: test_models.pyc
Only in averymd/improved-sniffle/tests: test_views.pyc
Binary files averymd/improved-sniffle/tests/urls.pyc and FutureProofGames/django_presskit/tests/urls.pyc differ
diff -r averymd/improved-sniffle/.travis.yml FutureProofGames/django_presskit/.travis.yml
<   - pip install .
>   - pip install .

Thank you so much for the comparison! Is there a way for me to perform a diff like that myself of what’s on the travis boxes?

The crux of the issue is:

Only in averymd/improved-sniffle/tests: test_dpk_util.pyc
Only in averymd/improved-sniffle/tests: test_models.pyc
Only in averymd/improved-sniffle/tests: test_views.pyc

Since python isn’t finding the source files, it’s not compiling them. :frowning: The source files are definitely on the server, of course.

As for the rest of the diff: python bytecode files will be different even if the underlying code is the same, unfortunately. Those commits also don’t quite line up (they include some later experiments/attempts in the FutureProofGames version).

I’d love to run it again with the current state of (build and (build In my working copies, a diff is showing the base files (no *.pyc) are the same aside from the additional LICENSE file.

Let me know if there’s a way I can do the diffs myself. Thank you!

To get the diffs, you can either:

  1. use this Docker image, which is a close approximation to what you are using, or
  2. have support enable the debug feature on your repo and clone repos and compare.

Update: the issue was caused by the repo having the exact same name as the library that’s installed. Changing the repo from django_presskit to django-presskit resolved the issue.

Thank you to everyone who offered suggestions and methods to troubleshoot this.