Skip to content

sys.modules[None] gets pseudo module when pytest skip condition is string #2103

Closed
@jaraco

Description

@jaraco

In pypa/setuptools#860, the test_sandbox tests started failing when another commit was made that invoked a pytest skip with a string expression, because that causes sys.modules to get a None key in that dict. This behavior can be minimally replicated thus:

$ cat > test_me.py
import sys
import pytest

@pytest.mark.skipif('os.environ.get("foo")')
def test_this():
    assert None not in sys.modules        
$ python -m rwt pytest -- -m pytest
Collecting pytest
  Using cached pytest-3.0.4-py2.py3-none-any.whl
Collecting py>=1.4.29 (from pytest)
  Using cached py-1.4.31-py2.py3-none-any.whl
Installing collected packages: py, pytest
Successfully installed py-1.4.31 pytest-3.0.4
====================================== test session starts =======================================
platform darwin -- Python 3.6.0b4, pytest-3.0.4, py-1.4.31, pluggy-0.4.0
rootdir: /Users/jaraco/issue-nnn, inifile: 
collected 1 items 

test_me.py F

============================================ FAILURES ============================================
___________________________________________ test_this ____________________________________________

    @pytest.mark.skipif('os.environ.get("foo")')
    def test_this():
>       assert None not in sys.modules
E       assert None not in {'builtins': <module 'builtins' (built-in)>, 'sys': <module 'sys' (built-in)>, '_frozen_importlib': <module 'importlib._bootstrap' (frozen)>, '_imp': <module '_imp' (built-in)>, ...}
E        +  where {'builtins': <module 'builtins' (built-in)>, 'sys': <module 'sys' (built-in)>, '_frozen_importlib': <module 'importlib._bootstrap' (frozen)>, '_imp': <module '_imp' (built-in)>, ...} = sys.modules

test_me.py:6: AssertionError
==================================== 1 failed in 0.04 seconds ====================================
$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions