From bde56a8246310d52737da4940649172ffa015648 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 4 Sep 2009 21:47:49 +0200 Subject: [PATCH] * fixing lots of remaining 3k compatibility issues, mostly with py.test itself. * removing very old import-tests that IIRC relate to a time when there was a custom import hook in use. * basically py.test internal tests pass now except py3/py2 distributed testing tests --HG-- branch : trunk --- py/execnet/rsync.py | 4 +- py/path/testing/test_local.py | 5 +- py/test/dist/mypickle.py | 18 +++++-- py/test/dist/testing/acceptance_test.py | 26 +++++---- py/test/dist/testing/test_mypickle.py | 22 ++++---- py/test/dist/testing/test_txnode.py | 5 +- py/test/looponfail/remote.py | 12 +++-- py/test/outcome.py | 4 +- py/test/plugin/pytest_capture.py | 4 +- py/test/plugin/pytest_execnetcleanup.py | 2 +- py/test/plugin/pytest_helpconfig.py | 2 +- py/test/plugin/pytest_hooklog.py | 2 +- py/test/plugin/pytest_pastebin.py | 4 +- py/test/plugin/pytest_pytester.py | 2 +- py/test/plugin/pytest_restdoc.py | 4 +- py/test/plugin/test_pytest_runner_xunit.py | 10 ++-- py/test/plugin/test_pytest_terminal.py | 12 ++--- .../testing/import_test/package/__init__.py | 1 - .../package/absolute_import_shared_lib.py | 1 - .../package/module_that_imports_shared_lib.py | 1 - .../testing/import_test/package/shared_lib.py | 3 -- .../import_test/package/test_import.py | 53 ------------------- py/test/testing/test_genitems.py | 4 +- py/test/testing/test_outcome.py | 9 +++- py/test/testing/test_pickling.py | 20 ++++--- 25 files changed, 102 insertions(+), 128 deletions(-) delete mode 100644 py/test/testing/import_test/package/__init__.py delete mode 100644 py/test/testing/import_test/package/absolute_import_shared_lib.py delete mode 100644 py/test/testing/import_test/package/module_that_imports_shared_lib.py delete mode 100644 py/test/testing/import_test/package/shared_lib.py delete mode 100644 py/test/testing/import_test/package/test_import.py diff --git a/py/execnet/rsync.py b/py/execnet/rsync.py index b565a6f78..0892f4cec 100644 --- a/py/execnet/rsync.py +++ b/py/execnet/rsync.py @@ -1,7 +1,7 @@ import py, os, stat -md5 = py.builtin._tryimport('hashlib.md5', 'md5.md5') -queue = py.builtin._tryimport('queue.Queue', 'Queue.Queue') +md5 = py.builtin._tryimport('hashlib', 'md5').md5 +Queue = py.builtin._tryimport('queue', 'Queue').Queue class RSync(object): """ This class allows to send a directory structure (recursively) diff --git a/py/path/testing/test_local.py b/py/path/testing/test_local.py index 46a91da73..a2616565c 100644 --- a/py/path/testing/test_local.py +++ b/py/path/testing/test_local.py @@ -39,8 +39,9 @@ class TestLocalPath(common.CommonFSTests): assert p == tmpdir def test_gethash(self, tmpdir): - md5 = py.builtin._tryimport('md5.md5', 'hashlib.md5') - sha = py.builtin._tryimport('sha.sha', 'hashlib.sha1') + md5 = py.builtin._tryimport('md5', 'hashlib').md5 + lib = py.builtin._tryimport('sha', 'hashlib') + sha = getattr(lib, 'sha1', getattr(lib, 'sha', None)) fn = tmpdir.join("testhashfile") data = 'hello'.encode('ascii') fn.write(data, mode="wb") diff --git a/py/test/dist/mypickle.py b/py/test/dist/mypickle.py index d14686e91..34d0a4d53 100644 --- a/py/test/dist/mypickle.py +++ b/py/test/dist/mypickle.py @@ -12,12 +12,22 @@ """ -from pickle import Pickler, Unpickler import py from py.__.execnet.gateway_base import Channel -import os +import sys, os #debug = open("log-mypickle-%d" % os.getpid(), 'w') +if sys.version_info >= (3,0): + makekey = lambda x: x + fromkey = lambda x: x + from pickle import _Pickler as Pickler + from pickle import _Unpickler as Unpickler +else: + makekey = str + fromkey = int + from pickle import Pickler, Unpickler + + class MyPickler(Pickler): """ Pickler with a custom memoize() to take care of unique ID creation. @@ -86,11 +96,11 @@ class ImmutablePickler: def _updatepicklememo(self): for x, obj in self._unpicklememo.items(): - self._picklememo[id(obj)] = (int(x), obj) + self._picklememo[id(obj)] = (fromkey(x), obj) def _updateunpicklememo(self): for key,obj in self._picklememo.values(): - key = str(key) + key = makekey(key) if key in self._unpicklememo: assert self._unpicklememo[key] is obj self._unpicklememo[key] = obj diff --git a/py/test/dist/testing/acceptance_test.py b/py/test/dist/testing/acceptance_test.py index 973f22079..f96d0fa43 100644 --- a/py/test/dist/testing/acceptance_test.py +++ b/py/test/dist/testing/acceptance_test.py @@ -6,24 +6,28 @@ class TestDistribution: p1.dirpath("__init__.py").write("") p1.dirpath("conftest.py").write(py.code.Source(""" import py - py.builtin.print_("importing conftest", __file__) + from py.builtin import print_ + print_("importing conftest", __file__) Option = py.test.config.Option option = py.test.config.addoptions("someopt", - Option('--someopt', action="store_true", dest="someopt", default=False)) + Option('--someopt', action="store_true", + dest="someopt", default=False)) dist_rsync_roots = ['../dir'] - py.builtin.print_("added options", option) - py.builtin.print_("config file seen from conftest", py.test.config) + print_("added options", option) + print_("config file seen from conftest", py.test.config) """)) p1.write(py.code.Source(""" - import py, conftest + import py + from %s import conftest + from py.builtin import print_ def test_1(): - py.builtin.print_("config from test_1", py.test.config) - py.builtin.print_("conftest from test_1", conftest.__file__) - py.builtin.print_("test_1: py.test.config.option.someopt", py.test.config.option.someopt) - py.builtin.print_("test_1: conftest", conftest) - py.builtin.print_("test_1: conftest.option.someopt", conftest.option.someopt) + print_("config from test_1", py.test.config) + print_("conftest from test_1", conftest.__file__) + print_("test_1: py.test.config.option.someopt", py.test.config.option.someopt) + print_("test_1: conftest", conftest) + print_("test_1: conftest.option.someopt", conftest.option.someopt) assert conftest.option.someopt - """)) + """ % p1.dirpath().purebasename )) result = testdir.runpytest('-d', '--tx=popen', p1, '--someopt') assert result.ret == 0 extra = result.stdout.fnmatch_lines([ diff --git a/py/test/dist/testing/test_mypickle.py b/py/test/dist/testing/test_mypickle.py index 6b11ca84d..05da9490b 100644 --- a/py/test/dist/testing/test_mypickle.py +++ b/py/test/dist/testing/test_mypickle.py @@ -1,8 +1,11 @@ import py -from py.__.test.dist.mypickle import ImmutablePickler, PickleChannel -from py.__.test.dist.mypickle import UnpickleError +import sys +Queue = py.builtin._tryimport('queue', 'Queue').Queue + +from py.__.test.dist.mypickle import ImmutablePickler, PickleChannel +from py.__.test.dist.mypickle import UnpickleError, makekey # first let's test some basic functionality def pytest_generate_tests(metafunc): @@ -24,8 +27,8 @@ def pytest_generate_tests(metafunc): metafunc.addcall(funcargs=dict(obj=obj, proto=proto)) def test_underlying_basic_pickling_mechanisms(picklemod): - f1 = py.io.TextIO() - f2 = py.io.TextIO() + f1 = py.io.BytesIO() + f2 = py.io.BytesIO() pickler1 = picklemod.Pickler(f1) unpickler1 = picklemod.Unpickler(f2) @@ -48,8 +51,9 @@ def test_underlying_basic_pickling_mechanisms(picklemod): pickler2.dump(d_other) f2.seek(0) - - unpickler1.memo = dict([(str(x), y) for x, y in pickler1.memo.values()]) + + unpickler1.memo = dict([(makekey(x), y) + for x, y in pickler1.memo.values()]) d_back = unpickler1.load() assert d is d_back @@ -177,7 +181,7 @@ class TestPickleChannelFunctional: channel.send(a2 is a1) """) channel = PickleChannel(channel) - queue = py.std.Queue.Queue() + queue = Queue() channel.setcallback(queue.put) a_received = queue.get(timeout=TESTTIMEOUT) assert isinstance(a_received, A) @@ -198,7 +202,7 @@ class TestPickleChannelFunctional: channel.send(a2 is a1) """) channel = PickleChannel(channel) - queue = py.std.Queue.Queue() + queue = Queue() channel.setcallback(queue.put, endmarker=-1) a_received = queue.get(timeout=TESTTIMEOUT) @@ -220,7 +224,7 @@ class TestPickleChannelFunctional: channel.send(a1) """) channel = PickleChannel(channel) - queue = py.std.Queue.Queue() + queue = Queue() a = channel.receive() channel._ipickle._unpicklememo.clear() channel.setcallback(queue.put, endmarker=-1) diff --git a/py/test/dist/testing/test_txnode.py b/py/test/dist/testing/test_txnode.py index 288207d78..9a03766cf 100644 --- a/py/test/dist/testing/test_txnode.py +++ b/py/test/dist/testing/test_txnode.py @@ -1,7 +1,8 @@ import py from py.__.test.dist.txnode import TXNode -Queue = py.builtin._tryimport("queue.Queue", "Queue.Queue") +queue = py.builtin._tryimport("queue", "Queue") +Queue = queue.Queue class EventQueue: def __init__(self, registry, queue=None): @@ -15,7 +16,7 @@ class EventQueue: while 1: try: eventcall = self.queue.get(timeout=timeout) - except py.std.Queue.Empty: + except queue.Empty: #print "node channel", self.node.channel #print "remoteerror", self.node.channel._getremoteerror() py.builtin.print_("seen events", events) diff --git a/py/test/looponfail/remote.py b/py/test/looponfail/remote.py index eaed38c4b..7967652a7 100644 --- a/py/test/looponfail/remote.py +++ b/py/test/looponfail/remote.py @@ -10,6 +10,7 @@ from __future__ import generators import py +import sys from py.__.test.session import Session from py.__.test.dist.mypickle import PickleChannel from py.__.test.looponfail import util @@ -70,14 +71,19 @@ class RemoteControl(object): channel = self.gateway.remote_exec(source=""" from py.__.test.dist.mypickle import PickleChannel from py.__.test.looponfail.remote import slave_runsession + outchannel = channel.gateway.newchannel() + channel.send(outchannel) channel = PickleChannel(channel) config, fullwidth, hasmarkup = channel.receive() + import sys + sys.stdout = sys.stderr = outchannel.makefile('w') slave_runsession(channel, config, fullwidth, hasmarkup) - """, stdout=out, stderr=out) - channel = PickleChannel(channel) + """) + remote_outchannel = channel.receive() + remote_outchannel.setcallback(out._file.write) + channel = self.channel = PickleChannel(channel) channel.send((self.config, out.fullwidth, out.hasmarkup)) self.trace("set up of slave session complete") - self.channel = channel def ensure_teardown(self): if hasattr(self, 'channel'): diff --git a/py/test/outcome.py b/py/test/outcome.py index 94bab7541..ba1e11d1d 100644 --- a/py/test/outcome.py +++ b/py/test/outcome.py @@ -25,7 +25,9 @@ class Passed(OutcomeException): pass class Skipped(OutcomeException): - pass + # XXX slighly hackish: on 3k we fake to live in the builtins + # in order to have Skipped exception printing shorter/nicer + __module__ = 'builtins' class Failed(OutcomeException): pass diff --git a/py/test/plugin/pytest_capture.py b/py/test/plugin/pytest_capture.py index 67442df21..0f586dd8d 100644 --- a/py/test/plugin/pytest_capture.py +++ b/py/test/plugin/pytest_capture.py @@ -67,8 +67,8 @@ per-test capturing. Here is an example test function: .. sourcecode:: python def test_myoutput(capsys): - print "hello" - print >>sys.stderr, "world" + print ("hello") + sys.stderr.write("world\n") out, err = capsys.readouterr() assert out == "hello\\n" assert err == "world\\n" diff --git a/py/test/plugin/pytest_execnetcleanup.py b/py/test/plugin/pytest_execnetcleanup.py index 2c5941430..28cbd9d69 100644 --- a/py/test/plugin/pytest_execnetcleanup.py +++ b/py/test/plugin/pytest_execnetcleanup.py @@ -48,7 +48,7 @@ def test_execnetplugin(testdir): sys._gw = py.execnet.PopenGateway() def test_world(): assert hasattr(sys, '_gw') - py.test.raises(KeyError, "sys._gw.exit()") # already closed + assert sys._gw not in sys._gw._cleanup._activegateways """, "-s", "--debug") reprec.assertoutcome(passed=2) diff --git a/py/test/plugin/pytest_helpconfig.py b/py/test/plugin/pytest_helpconfig.py index 49109442f..d87372b7c 100644 --- a/py/test/plugin/pytest_helpconfig.py +++ b/py/test/plugin/pytest_helpconfig.py @@ -30,7 +30,7 @@ def pytest_configure(__multicall__, config): tw.sep("-") options = [opt for opt in options if opt._long_opts] - options.sort(lambda x, y: cmp(x._long_opts, y._long_opts)) + options.sort(key=lambda x: x._long_opts) for opt in options: if not opt._long_opts: continue diff --git a/py/test/plugin/pytest_hooklog.py b/py/test/plugin/pytest_hooklog.py index 96ed854ab..d27d1e098 100644 --- a/py/test/plugin/pytest_hooklog.py +++ b/py/test/plugin/pytest_hooklog.py @@ -8,7 +8,7 @@ def pytest_addoption(parser): def pytest_configure(config): hooklog = config.getvalue("hooklog") if hooklog: - config._hooklogfile = open(hooklog, 'w', 0) + config._hooklogfile = open(hooklog, 'w') config._hooklog_oldperformcall = config.hook._performcall config.hook._performcall = (lambda name, multicall: logged_call(name=name, multicall=multicall, config=config)) diff --git a/py/test/plugin/pytest_pastebin.py b/py/test/plugin/pytest_pastebin.py index b9d67e86a..1760b3a57 100644 --- a/py/test/plugin/pytest_pastebin.py +++ b/py/test/plugin/pytest_pastebin.py @@ -37,7 +37,7 @@ def pytest_configure(__multicall__, config): import tempfile __multicall__.execute() if config.option.pastebin == "all": - config._pastebinfile = tempfile.TemporaryFile() + config._pastebinfile = tempfile.TemporaryFile('w+') tr = config.pluginmanager.impname2plugin['terminalreporter'] oldwrite = tr._tw.write def tee_write(s, **kwargs): @@ -53,7 +53,7 @@ def pytest_unconfigure(config): del config._pastebinfile proxyid = getproxy().newPaste("python", sessionlog) pastebinurl = "%s%s" % (url.show, proxyid) - print >>sys.stderr, "session-log:", pastebinurl + sys.stderr.write("session-log: %s" % pastebinurl) tr = config.pluginmanager.impname2plugin['terminalreporter'] del tr._tw.__dict__['write'] diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 76090035f..16b6ebd81 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -379,7 +379,7 @@ class ReportRecorder(object): return passed, skipped, failed def countoutcomes(self): - return map(len, self.listoutcomes()) + return [len(x) for x in self.listoutcomes()] def assertoutcome(self, passed=0, skipped=0, failed=0): realpassed, realskipped, realfailed = self.listoutcomes() diff --git a/py/test/plugin/pytest_restdoc.py b/py/test/plugin/pytest_restdoc.py index b85894799..34dada0b4 100644 --- a/py/test/plugin/pytest_restdoc.py +++ b/py/test/plugin/pytest_restdoc.py @@ -426,7 +426,7 @@ class TestDoctest: >>> assert abspath >>> i=3 - >>> print i + >>> print (i) 3 yes yes @@ -450,7 +450,7 @@ class TestDoctest: def test_doctest_indentation(self, testdir): footxt = testdir.maketxtfile(foo= - '..\n >>> print "foo\\n bar"\n foo\n bar\n') + '..\n >>> print ("foo\\n bar")\n foo\n bar\n') reprec = testdir.inline_run(footxt) passed, skipped, failed = reprec.countoutcomes() assert failed == 0 diff --git a/py/test/plugin/test_pytest_runner_xunit.py b/py/test/plugin/test_pytest_runner_xunit.py index 18ff73d50..a610c31b1 100644 --- a/py/test/plugin/test_pytest_runner_xunit.py +++ b/py/test/plugin/test_pytest_runner_xunit.py @@ -99,22 +99,22 @@ def test_func_generator_setup(testdir): import sys def setup_module(mod): - print "setup_module" + print ("setup_module") mod.x = [] def setup_function(fun): - print "setup_function" + print ("setup_function") x.append(1) def teardown_function(fun): - print "teardown_function" + print ("teardown_function") x.pop() def test_one(): assert x == [1] def check(): - print "check" - print >>sys.stderr, "e" + print ("check") + sys.stderr.write("e\\n") assert x == [1] yield check assert x == [1] diff --git a/py/test/plugin/test_pytest_terminal.py b/py/test/plugin/test_pytest_terminal.py index 6b3522628..598e7e546 100644 --- a/py/test/plugin/test_pytest_terminal.py +++ b/py/test/plugin/test_pytest_terminal.py @@ -171,7 +171,7 @@ class TestTerminal: def g(): raise IndexError def test_func(): - print 6*7 + print (6*7) g() # --calling-- """) for tbopt in ["long", "short", "no"]: @@ -179,9 +179,9 @@ class TestTerminal: result = testdir.runpytest('--tb=%s' % tbopt) s = result.stdout.str() if tbopt == "long": - assert 'print 6*7' in s + assert 'print (6*7)' in s else: - assert 'print 6*7' not in s + assert 'print (6*7)' not in s if tbopt != "no": assert '--calling--' in s assert 'IndexError' in s @@ -411,7 +411,7 @@ class TestFixtureReporting: def test_setup_fixture_error(self, testdir): p = testdir.makepyfile(""" def setup_function(function): - print "setup func" + print ("setup func") assert 0 def test_nada(): pass @@ -431,7 +431,7 @@ class TestFixtureReporting: def test_nada(): pass def teardown_function(function): - print "teardown func" + print ("teardown func") assert 0 """) result = testdir.runpytest() @@ -450,7 +450,7 @@ class TestFixtureReporting: assert 0, "failingfunc" def teardown_function(function): - print "teardown func" + print ("teardown func") assert False """) result = testdir.runpytest() diff --git a/py/test/testing/import_test/package/__init__.py b/py/test/testing/import_test/package/__init__.py deleted file mode 100644 index 792d60054..000000000 --- a/py/test/testing/import_test/package/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# diff --git a/py/test/testing/import_test/package/absolute_import_shared_lib.py b/py/test/testing/import_test/package/absolute_import_shared_lib.py deleted file mode 100644 index 032264086..000000000 --- a/py/test/testing/import_test/package/absolute_import_shared_lib.py +++ /dev/null @@ -1 +0,0 @@ -from package import shared_lib diff --git a/py/test/testing/import_test/package/module_that_imports_shared_lib.py b/py/test/testing/import_test/package/module_that_imports_shared_lib.py deleted file mode 100644 index d9def145d..000000000 --- a/py/test/testing/import_test/package/module_that_imports_shared_lib.py +++ /dev/null @@ -1 +0,0 @@ -import shared_lib diff --git a/py/test/testing/import_test/package/shared_lib.py b/py/test/testing/import_test/package/shared_lib.py deleted file mode 100644 index 726e4298f..000000000 --- a/py/test/testing/import_test/package/shared_lib.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -Just a dummy module -""" diff --git a/py/test/testing/import_test/package/test_import.py b/py/test/testing/import_test/package/test_import.py deleted file mode 100644 index 3d7ba6ac9..000000000 --- a/py/test/testing/import_test/package/test_import.py +++ /dev/null @@ -1,53 +0,0 @@ -import sys -import os -import py - -def setup_module(mod=None): - if mod is None: - f = __file__ - else: - f = mod.__file__ - sys.path.append(os.path.dirname(os.path.dirname(f))) - -def teardown_module(mod=None): - if mod is None: - f = __file__ - else: - f = mod.__file__ - sys.path.remove(os.path.dirname(os.path.dirname(f))) - -def test_import(): - global shared_lib, module_that_imports_shared_lib - import shared_lib - from package import shared_lib as shared_lib2 - import module_that_imports_shared_lib - import absolute_import_shared_lib - all_modules = [ - ('shared_lib', shared_lib), - ('shared_lib2', shared_lib2), - ('module_that_imports_shared_lib', - module_that_imports_shared_lib.shared_lib), - ('absolute_import_shared_lib', - absolute_import_shared_lib.shared_lib), - ] - bad_matches = [] - while all_modules: - name1, mod1 = all_modules[0] - all_modules = all_modules[1:] - for name2, mod2 in all_modules: - if mod1 is not mod2: - bad_matches.append((name1, mod1, name2, mod2)) - for name1, mod1, name2, mod2 in bad_matches: - print("These modules should be identical:") - print(" %s:" % name1) - print(" ", mod1) - print(" %s:" % name2) - print(" ", mod2) - py.builtin.print_() - if bad_matches: - assert False - -if __name__ == "__main__": - setup_module() - test_import - teardown_module() diff --git a/py/test/testing/test_genitems.py b/py/test/testing/test_genitems.py index 387709701..2857f1685 100644 --- a/py/test/testing/test_genitems.py +++ b/py/test/testing/test_genitems.py @@ -26,12 +26,12 @@ class Test_genitems: def test_subdir_conftest_error(self, testdir): tmp = testdir.tmpdir - tmp.ensure("sub", "conftest.py").write("raise SyntaxError()\n") + tmp.ensure("sub", "conftest.py").write("raise SyntaxError('x')\n") items, reprec = testdir.inline_genitems(tmp) collectionfailures = reprec.getfailedcollections() assert len(collectionfailures) == 1 ev = collectionfailures[0] - assert ev.longrepr.reprcrash.message.startswith("SyntaxError") + assert "SyntaxError: x" in ev.longrepr.reprcrash.message def test_example_items1(self, testdir): p = testdir.makepyfile(''' diff --git a/py/test/testing/test_outcome.py b/py/test/testing/test_outcome.py index 078f5b5f8..585bfdd6a 100644 --- a/py/test/testing/test_outcome.py +++ b/py/test/testing/test_outcome.py @@ -1,6 +1,6 @@ import py -import marshal +import sys class TestRaises: def test_raises(self): @@ -42,3 +42,10 @@ def test_pytest_exit(): excinfo = py.code.ExceptionInfo() assert excinfo.errisinstance(KeyboardInterrupt) +def test_exception_printing_skip(): + try: + py.test.skip("hello") + except Exception: + excinfo = py.code.ExceptionInfo() + s = excinfo.exconly(tryshort=True) + assert s.startswith("Skipped") diff --git a/py/test/testing/test_pickling.py b/py/test/testing/test_pickling.py index 8d8093898..0096b1f09 100644 --- a/py/test/testing/test_pickling.py +++ b/py/test/testing/test_pickling.py @@ -1,4 +1,5 @@ import py +import pickle def setglobals(request): oldconfig = py.test.config @@ -129,44 +130,41 @@ class TestConfigPickling: assert option.gdest == 11 def test_config_picklability(self, testdir): - import cPickle config = testdir.parseconfig() - s = cPickle.dumps(config) - newconfig = cPickle.loads(s) + s = pickle.dumps(config) + newconfig = pickle.loads(s) assert hasattr(newconfig, "topdir") assert newconfig.topdir == py.path.local() def test_collector_implicit_config_pickling(self, testdir): - from cPickle import Pickler, Unpickler tmpdir = testdir.tmpdir testdir.chdir() testdir.makepyfile(hello="def test_x(): pass") config = testdir.parseconfig(tmpdir) col = config.getfsnode(config.topdir) - io = py.io.TextIO() - pickler = Pickler(io) + io = py.io.BytesIO() + pickler = pickle.Pickler(io) pickler.dump(col) io.seek(0) - unpickler = Unpickler(io) + unpickler = pickle.Unpickler(io) col2 = unpickler.load() assert col2.name == col.name assert col2.listnames() == col.listnames() def test_config_and_collector_pickling(self, testdir): - from pickle import Pickler, Unpickler tmpdir = testdir.tmpdir dir1 = tmpdir.ensure("somedir", dir=1) config = testdir.parseconfig() col = config.getfsnode(config.topdir) col1 = col.join(dir1.basename) assert col1.parent is col - io = py.io.TextIO() - pickler = Pickler(io) + io = py.io.BytesIO() + pickler = pickle.Pickler(io) pickler.dump(col) pickler.dump(col1) pickler.dump(col) io.seek(0) - unpickler = Unpickler(io) + unpickler = pickle.Unpickler(io) topdir = tmpdir.ensure("newtopdir", dir=1) topdir.ensure("somedir", dir=1) old = topdir.chdir()