From 90be44c8128a5a293f3045eea6da27643809081a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 19 Apr 2017 08:19:19 -0300 Subject: [PATCH] Document PYTEST_DONT_REWRITE Fixes #2203 --- doc/en/assert.rst | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/en/assert.rst b/doc/en/assert.rst index b674f90b0..1d5def87b 100644 --- a/doc/en/assert.rst +++ b/doc/en/assert.rst @@ -270,12 +270,21 @@ supporting modules which are not themselves test modules will not be rewritten. .. note:: - ``pytest`` rewrites test modules on import. It does this by using an import - hook to write new pyc files. Most of the time this works transparently. + ``pytest`` rewrites test modules on import by using an import + hook to write new ``pyc`` files. Most of the time this works transparently. However, if you are messing with import yourself, the import hook may - interfere. If this is the case, use ``--assert=plain``. Additionally, - rewriting will fail silently if it cannot write new pycs, i.e. in a read-only - filesystem or a zipfile. + interfere. + + If this is the case you have two options: + + * Disable rewriting for a specific module by adding the string + ``PYTEST_DONT_REWRITE`` to its docstring. + + * Disable rewriting for all modules by using ``--assert=plain``. + + Additionally, rewriting will fail silently if it cannot write new ``.pyc`` files, + i.e. in a read-only filesystem or a zipfile. + For further information, Benjamin Peterson wrote up `Behind the scenes of pytest's new assertion rewriting `_.