import py def exec_test(get_channel, source): channel = get_channel(source) count = 0.0 wait = 0.4 while not channel.isclosed(): count += wait py.std.time.sleep(wait) if count > 2: #seconds print '+' * 50, '\n', 'gateway code:\n', '+' * 50 print py.code.Source(get_channel) print '+' * 50, '\n', 'remote:\n', '+' * 50 print source py.test.fail('channel is still open') channel.gateway.exit() def get_channel_auto(source): # autoclose = True in gateway.remote_exec gateway = py.execnet.PopenGateway() return gateway.remote_exec(source = source) def get_channel_explicit(source): # autoclose = False in gateway.remote_exec gateway = py.execnet.PopenGateway() channel = gateway.newchannel() return gateway.remote_exec(channel = channel, source = source) def get_source(do_import = True, do_config = True, close_channel = True): """ Create variations of this code: import py import py.__.test.item # enabled by do_import temp = py.test.Config.parse([]) # enabled by do_config channel.close() # enabled by close_channel """ s = py.code.Source('import py', do_import and 'import py.__.test.item' or '', do_config and 'temp = py.test.Config.parse([])' or '', close_channel and 'channel.close()' or '') return s def test_combinations(): for func in [get_channel_explicit, get_channel_auto]: for do_import in [True, False]: for close_channel in [True, False]: for do_config in [True, False]: source = get_source(do_import = do_import, do_config = do_config, close_channel = close_channel) yield exec_test, func, source def test_new_execnet_import_issue(): gateway = py.execnet.PopenGateway() channel = gateway.newchannel() gateway.remote_exec(channel = channel, source = ''' import py import py.__.test.item #enable/disable temp = py.test.Config.parse([]) #enable/disable #channel.close() #enable/disable ''') count = 0 wait = 0.4 while not channel.isclosed(): count += wait py.std.time.sleep(wait) if count > 2: # seconds py.test.fail('channel is still open') channel.gateway.exit()