From 2283052fd01138863a5741d84f358fdbea501bd9 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 27 Oct 2022 14:56:30 +0200 Subject: DOC: Update TESTS.rst to use the correct names Not actually sure that setup_module() is what was wanted here, but it works? Mention a bit more about actual pytest fixtures. --- doc/TESTS.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/TESTS.rst b/doc/TESTS.rst index 0d8137f4a..9c5e8571f 100644 --- a/doc/TESTS.rst +++ b/doc/TESTS.rst @@ -178,30 +178,33 @@ Similarly for methods:: Easier setup and teardown functions / methods --------------------------------------------- -Testing looks for module-level or class-level setup and teardown functions by -name; thus:: +Testing looks for module-level or class method-level setup and teardown +functions by name; thus:: - def setup(): + def setup_module(): """Module-level setup""" print('doing setup') - def teardown(): + def teardown_module(): """Module-level teardown""" print('doing teardown') class TestMe: - def setup(): + def setup_method(self): """Class-level setup""" print('doing setup') - def teardown(): + def teardown_method(): """Class-level teardown""" print('doing teardown') Setup and teardown functions to functions and methods are known as "fixtures", -and their use is not encouraged. +and they should be used sparingly. +``pytest`` supports more general fixture at various scopes which may be used +automatically via special arguments. For example, the special argument name +``tmpdir`` is used in test to create a temporary directory. Parametric tests ---------------- -- cgit v1.2.1