예제 #1
0
    def test_context_exit_status(self):
        # exit status of the child process is available as a context attr
        with SplitExec() as c:
            pass
        assert c.exit_status == 0

        exit_status = random.randint(1, 255)
        with SplitExec() as c:
            sys.exit(exit_status)
        assert c.exit_status == exit_status
예제 #2
0
 def test_context_process(self):
     # code inside the with statement is run in a separate process
     pid = os.getpid()
     with SplitExec() as c:
         pass
     assert c.childpid is not None
     assert pid != c.childpid
예제 #3
0
    def test_context_locals(self):
        # code inside the with statement returns modified, pickleable locals
        # via 'locals' attr of the context manager
        a = 1
        with SplitExec() as c:
            assert a == 1
            a = 2
            assert a == 2
            b = 3
        # changes to locals aren't propagated back
        assert a == 1
        assert 'b' not in locals()
        # but they're accessible via the 'locals' attr
        expected = {'a': 2, 'b': 3}
        for k, v in expected.items():
            assert c.locals[k] == v

        # make sure unpickleables don't cause issues
        with SplitExec() as c:
            func = lambda x: x
            import sys
            a = 4
        assert c.locals == {'a': 4}
예제 #4
0
 def test_context_exceptions(self):
     # exceptions in the child process are sent back to the parent and re-raised
     with pytest.raises(IOError) as e:
         with SplitExec() as c:
             raise IOError(errno.EBUSY, 'random error')
     assert e.value.errno == errno.EBUSY