From d30ba9ff5e1cddbeff3f23cbc8077a0d3a4fc806 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Mon, 2 Oct 2017 11:46:08 -0400 Subject: [PATCH 1/4] Document how to run @ddt.data methods with pytest --- docs/testing.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/testing.rst b/docs/testing.rst index c0c978c18a..c61f83442f 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -263,6 +263,22 @@ This command runs a single python unit test within a specified file. pytest common/lib/xmodule/xmodule/tests/test_stringify.py::test_stringify +This command runs a single python unit test method within a specified TestCase +class within a specified file. + +:: + + pytest common/lib/xmodule/xmodule/tests/test_stringify.py::TestCase::test_stringify + +Note: if the method has an `@ddt.data` decorator, ddt will create multiple +methods with the same prefix name and each individual data input as the suffix +(e.g. `test_stringify_1_foo`). To test all of the ddt.data variations of the +same test method, use the pytest `-k` option. + +:: + + pytest common/lib/xmodule/xmodule/tests/test_stringify.py::TestCase -k test_stringify + This is an example of how to run a single test and get stdout shown immediately, with proper env config. From 352a652d117373b7ef63a723b562a8c8991eb739 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 3 Oct 2017 11:46:41 -0400 Subject: [PATCH 2/4] Address PR comments --- docs/testing.rst | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/docs/testing.rst b/docs/testing.rst index c61f83442f..78f4ddc18f 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -257,28 +257,41 @@ For example, this command runs a single python unit test file. pytest common/lib/xmodule/xmodule/tests/test_stringify.py -This command runs a single python unit test within a specified file. + +To select tests to run based on their name, provide an expression to the `pytest +-k option +` +which performs a substring match on test names. :: - pytest common/lib/xmodule/xmodule/tests/test_stringify.py::test_stringify + pytest common/lib/xmodule/xmodule/tests/test_stringify.py -k test_stringify -This command runs a single python unit test method within a specified TestCase -class within a specified file. +Alternatively, you can select tests based on their `node ID +` directly, +which is useful when you need to run only one of mutliple tests with the same +name in different classes or files. -:: - - pytest common/lib/xmodule/xmodule/tests/test_stringify.py::TestCase::test_stringify - -Note: if the method has an `@ddt.data` decorator, ddt will create multiple -methods with the same prefix name and each individual data input as the suffix -(e.g. `test_stringify_1_foo`). To test all of the ddt.data variations of the -same test method, use the pytest `-k` option. +This command runs any python unit test method that matches the substring +`test_stringify` within a specified TestCass class within a specified file. :: pytest common/lib/xmodule/xmodule/tests/test_stringify.py::TestCase -k test_stringify +Note: if the method has an `@ddt.data` decorator, ddt will create multiple +methods with the same prefix name and each individual data input as the suffix +(e.g. `test_stringify_1_foo`). To test all of the ddt.data variations of the +same test method, pass the prefix name to the pytest `-k` option. + +If you need to run only one of the test variations, you can the get the +name of all test methods in a class, file, or project, including all ddt.data +variations, by running pytest with `--collectonly`. + +:: + + pytest common/lib/xmodule/xmodule/tests/test_stringify.py --collectonly + This is an example of how to run a single test and get stdout shown immediately, with proper env config. From 3a8ca1aa3b76e43f37e9ce42d57e6acfd1274c38 Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 3 Oct 2017 11:49:12 -0400 Subject: [PATCH 3/4] RST is confusing --- docs/testing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/testing.rst b/docs/testing.rst index 78f4ddc18f..866c5ddd47 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -260,7 +260,7 @@ For example, this command runs a single python unit test file. To select tests to run based on their name, provide an expression to the `pytest -k option -` +`__ which performs a substring match on test names. :: @@ -268,7 +268,7 @@ which performs a substring match on test names. pytest common/lib/xmodule/xmodule/tests/test_stringify.py -k test_stringify Alternatively, you can select tests based on their `node ID -` directly, +`__ directly, which is useful when you need to run only one of mutliple tests with the same name in different classes or files. From 9d7c3f92c10f379c74271ef7fc95a1b865b603dd Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Tue, 3 Oct 2017 16:12:11 -0400 Subject: [PATCH 4/4] Spelling mistake fix --- docs/testing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/testing.rst b/docs/testing.rst index 866c5ddd47..78282e6a32 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -273,7 +273,7 @@ which is useful when you need to run only one of mutliple tests with the same name in different classes or files. This command runs any python unit test method that matches the substring -`test_stringify` within a specified TestCass class within a specified file. +`test_stringify` within a specified TestCase class within a specified file. ::