Issues

Issue #5 resolved

Test failure with Python 3.4

Arfrever Frehtes Taifersar Arahesis
created an issue

test_initpkg_not_transfers_not_existing_attrs() fails with Python 3.4. All tests pass with older versions of Python.

$ py.test-3.4
/usr/lib64/python3.4/imp.py:32: PendingDeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  PendingDeprecationWarning)
==================================================================== test session starts ====================================================================
platform linux -- Python 3.4.1 -- py-1.4.20 -- pytest-2.5.2
collected 34 items 

test_apipkg.py ...............F..................

========================================================================= FAILURES ==========================================================================
_______________________________________________________ test_initpkg_not_transfers_not_existing_attrs _______________________________________________________

monkeypatch = <_pytest.monkeypatch.monkeypatch object at 0x7f822db714e0>

    def test_initpkg_not_transfers_not_existing_attrs(monkeypatch):
        mod = ModuleType('hello')
        mod.__file__ = "hello.py"
        monkeypatch.setitem(sys.modules, 'hello', mod)
        apipkg.initpkg('hello', {})
        newmod = sys.modules['hello']
        assert newmod != mod
        assert newmod.__file__ == py.path.local(mod.__file__)
>       assert not hasattr(newmod, '__loader__')
E       assert not True
E        +  where True = hasattr(<ApiModule 'hello' from '/tmp/apipkg/hello.py'>, '__loader__')

test_apipkg.py:253: AssertionError
============================================================ 1 failed, 33 passed in 1.10 seconds ============================================================

http://docs.python.org/3.4/whatsnew/3.4.html:

The module type now initializes the __package__ and __loader__ attributes to None by default. To determine if these attributes were set in a backwards-compatible fashion, use e.g. getattr(module, '__loader__', None) is not None. (issue 17115.)

Comments (2)

  1. Arfrever Frehtes Taifersar Arahesis reporter

    Potential fix:

    --- test_apipkg.py
    +++ test_apipkg.py
    @@ -250,7 +250,10 @@
         newmod = sys.modules['hello']
         assert newmod != mod
         assert newmod.__file__ == py.path.local(mod.__file__)
    -    assert not hasattr(newmod, '__loader__')
    +    if sys.version_info[:2] < (3, 4):
    +        assert not hasattr(newmod, '__loader__')
    +    else:
    +        assert hasattr(newmod, '__loader__')
         assert not hasattr(newmod, '__path__')
    
  2. Log in to comment