From ba5a2955443313dd4b49ce539508ef5be93966b2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Oct 2018 14:53:41 -0300 Subject: [PATCH 1/4] Fix hook name in deprecations.rst As mentioned in https://github.com/pytest-dev/pytest/issues/4128#issuecomment-430690498 --- doc/en/deprecations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 30746d035..3a06c7d5f 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -68,7 +68,7 @@ Using ``Class`` in custom Collectors .. deprecated:: 3.9 Using objects named ``"Class"`` as a way to customize the type of nodes that are collected in ``Collector`` -subclasses has been deprecated. Users instead should use ``pytest_collect_make_item`` to customize node types during +subclasses has been deprecated. Users instead should use ``pytest_pycollect_makeitem`` to customize node types during collection. This issue should affect only advanced plugins who create new collection types, so if you see this warning From cc335d44a09e7d3e204b9304f4c0361ebce4c726 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 17 Oct 2018 20:43:27 +0200 Subject: [PATCH 2/4] fix #4179 - bring back the current testrun symlink --- changelog/4179.bugfix.rst | 1 + src/_pytest/pathlib.py | 21 +++++++++++++++++++++ testing/test_tmpdir.py | 4 ++++ 3 files changed, 26 insertions(+) create mode 100644 changelog/4179.bugfix.rst diff --git a/changelog/4179.bugfix.rst b/changelog/4179.bugfix.rst new file mode 100644 index 000000000..6f7467f50 --- /dev/null +++ b/changelog/4179.bugfix.rst @@ -0,0 +1 @@ +Restore the tmpdir behaviour of symlinking the current test run. diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py index cda5e9947..081fce904 100644 --- a/src/_pytest/pathlib.py +++ b/src/_pytest/pathlib.py @@ -100,6 +100,26 @@ else: _max = max +def _force_symlink(root, target, link_to): + """helper to create the current symlink + + its full of race conditions that are reasonably ok to ignore + for the contex of best effort linking to the latest testrun + + the presumption being thatin case of much parallelism + the inaccuracy is going to be acceptable + """ + current_symlink = root.joinpath(target) + try: + current_symlink.unlink() + except OSError: + pass + try: + current_symlink.symlink_to(link_to) + except Exception: + pass + + def make_numbered_dir(root, prefix): """create a directory with a increased number as suffix for the given prefix""" for i in range(10): @@ -112,6 +132,7 @@ def make_numbered_dir(root, prefix): except Exception: pass else: + _force_symlink(root, prefix + "current", new_path) return new_path else: raise EnvironmentError( diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index 9f4158eb7..441714528 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -196,6 +196,10 @@ class TestNumberedDir(object): assert d.name.startswith(self.PREFIX) assert d.name.endswith(str(i)) + symlink = tmp_path.joinpath(self.PREFIX + "current") + assert symlink.is_symlink() + assert symlink.resolve() == d.resolve() + def test_cleanup_lock_create(self, tmp_path): d = tmp_path.joinpath("test") d.mkdir() From 8dca8f3c9f3ca09bfa11fb1b322a4707c098bab6 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 17 Oct 2018 21:16:44 +0200 Subject: [PATCH 3/4] fix test_cleanup_keep for expecting symlinks --- testing/test_tmpdir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index 441714528..f1b6fe424 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -248,7 +248,7 @@ class TestNumberedDir(object): def test_cleanup_keep(self, tmp_path): self._do_cleanup(tmp_path) - a, b = tmp_path.iterdir() + a, b = (x for x in tmp_path.iterdir() if not x.is_symlink()) print(a, b) def test_cleanup_locked(self, tmp_path): From 56dd7bc551f739a00795ab866578ce3789fa572e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 17 Oct 2018 21:39:23 +0200 Subject: [PATCH 4/4] TestNumberedDir: ignore that symlinks arent created on windows --- testing/test_tmpdir.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/test_tmpdir.py b/testing/test_tmpdir.py index f1b6fe424..3c413e7c2 100644 --- a/testing/test_tmpdir.py +++ b/testing/test_tmpdir.py @@ -197,8 +197,10 @@ class TestNumberedDir(object): assert d.name.endswith(str(i)) symlink = tmp_path.joinpath(self.PREFIX + "current") - assert symlink.is_symlink() - assert symlink.resolve() == d.resolve() + if symlink.exists(): + # unix + assert symlink.is_symlink() + assert symlink.resolve() == d.resolve() def test_cleanup_lock_create(self, tmp_path): d = tmp_path.joinpath("test")