From 8d1903fed386e5d2060c8a61339f0dd9d4df3b8f Mon Sep 17 00:00:00 2001 From: Tarcisio Fischer Date: Tue, 5 Sep 2017 15:22:04 -0300 Subject: [PATCH 1/2] Avoid creating arbitrary filenames for tmpdir on Testdir's constructor Fixes #2751 --- _pytest/pytester.py | 10 +--------- testing/test_collection.py | 1 - 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index fc9b8d9cb..573640014 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -412,16 +412,8 @@ class Testdir: def __init__(self, request, tmpdir_factory): self.request = request self._mod_collections = WeakKeyDictionary() - # XXX remove duplication with tmpdir plugin - basetmp = tmpdir_factory.ensuretemp("testdir") name = request.function.__name__ - for i in range(100): - try: - tmpdir = basetmp.mkdir(name + str(i)) - except py.error.EEXIST: - continue - break - self.tmpdir = tmpdir + self.tmpdir = tmpdir_factory.mktemp(name, numbered=True) self.plugins = [] self._savesyspath = (list(sys.path), list(sys.meta_path)) self._savemodulekeys = set(sys.modules) diff --git a/testing/test_collection.py b/testing/test_collection.py index 5d1654410..ab0c93bae 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -569,7 +569,6 @@ class Test_getinitialnodes(object): col = testdir.getnode(config, x) assert isinstance(col, pytest.Module) assert col.name == 'x.py' - assert col.parent.name == testdir.tmpdir.basename assert col.parent.parent is None for col in col.listchain(): assert col.config is config From de6b41e318a69d723c2e43aa6253991cd9921d5b Mon Sep 17 00:00:00 2001 From: Tarcisio Fischer Date: Tue, 5 Sep 2017 14:33:06 -0300 Subject: [PATCH 2/2] Update changelog and AUTHORS files, following the CONTRIBUTING guidelines --- AUTHORS | 1 + changelog/2751.bugfix | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog/2751.bugfix diff --git a/AUTHORS b/AUTHORS index cc4aaa6ad..717c19b2e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -161,6 +161,7 @@ Stefan Zimmermann Stefano Taschini Steffen Allner Stephan Obermann +Tarcisio Fischer Tareq Alayan Ted Xiao Thomas Grainger diff --git a/changelog/2751.bugfix b/changelog/2751.bugfix new file mode 100644 index 000000000..76004a653 --- /dev/null +++ b/changelog/2751.bugfix @@ -0,0 +1 @@ +``testdir`` now uses use the same method used by ``tmpdir`` to create its temporary directory. This changes the final structure of the ``testdir`` directory slightly, but should not affect usage in normal scenarios and avoids a number of potential problems. \ No newline at end of file