From ab39502c98f40c03a2956dcf6c6b9daf5ee41a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 26 Jul 2019 02:23:14 +0200 Subject: [PATCH] In test_xfail_handling, only remove __pycache__ if it exists Previously, the test failed when the directory was not present, which could have been caused for example by invoking the tests with PYTHONDONTWRITEBYTECODE=1. Fixes https://github.com/pytest-dev/pytest/issues/5664 --- changelog/5664.trivial.rst | 2 ++ testing/test_stepwise.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog/5664.trivial.rst diff --git a/changelog/5664.trivial.rst b/changelog/5664.trivial.rst new file mode 100644 index 000000000..3928454ef --- /dev/null +++ b/changelog/5664.trivial.rst @@ -0,0 +1,2 @@ +When invoking pytest's own testsuite with ``PYTHONDONTWRITEBYTECODE=1``, +the ``test_xfail_handling`` test no longer fails. diff --git a/testing/test_stepwise.py b/testing/test_stepwise.py index 591d67b6c..f61425b6b 100644 --- a/testing/test_stepwise.py +++ b/testing/test_stepwise.py @@ -207,7 +207,8 @@ def test_d(): pass # because we are writing to the same file, mtime might not be affected enough to # invalidate the cache, making this next run flaky - testdir.tmpdir.join("__pycache__").remove() + if testdir.tmpdir.join("__pycache__").exists(): + testdir.tmpdir.join("__pycache__").remove() testdir.makepyfile(contents.format(assert_value="0", strict="True")) result = testdir.runpytest("--sw", "-v") result.stdout.fnmatch_lines(