Issue #301 resolved

[Patch] Python 3 namespace packages

Stefan H. Holek
created an issue

When use_2to3=True is used together with namespace packages, the 'test' command always tries to run tests from the source directory, not the build/lib directory.

This is because the modules under test have already been imported earlier (from the source directory) by find_packages and/or 2to3, and the test loader does not re-import them from the build/lib directory.

To fix this problem, the proposed patch deletes modules under test from sys.modules prior to invoking the test loader, forcing the test loader to re-import them.

Patch 'test': [[https://bitbucket.org/stefanholek/distribute/changeset/5c32eafbe8f1cd1258df98496a5eaa6f]]

Comments (5)

  1. Lennart Regebro

    I was surprised at this, because I know that this is not how it used to be, and I'm in fact unable to reproduce this problem. I've added a test case and it works. The test is clearly run from the build/lib even with namespace packages.

    If you could provide an example of this happening, I'll continue to look into it.

  2. Stefan H. Holek reporter

    For me it fails reliably, even in the simplest of cases. See attached package.

    $ tar xzf test.namespace.package.tgz
    $ cd test.namespace.package
    $ virtualenv3.3 .
    $ ./bin/easy_install -U ../distribute-trunk
    $ ./bin/python setup.py develop
    $ ./bin/python setup.py -q test
    
      File "/usr/local/python3.3/lib/python3.3/unittest/loader.py", line 96, in loadTestsFromName
        module = __import__('.'.join(parts_copy))
      File "/Users/stefan/sandbox/test.namespace.package/test/namespace/package/tests/test_namespace.py", line 15
        except TypeError, e:
                        ^
    SyntaxError: invalid syntax
    

    With my patch applied things work as expected.

  3. Log in to comment