From c3c3a9cf4c0adad2cc54dbde0e40dc8cfa1ede1b Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sun, 19 Jul 2020 23:12:59 +0300 Subject: [PATCH 1/7] doc: note about mutation of parametrized values Fix #7514 by augmenting Note with behaviour when parametrized values are mutated (changes are reflected in subsequent test-case calls). --- doc/en/parametrize.rst | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index c8b0bf4f35a..5e7e2ae63c6 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -81,17 +81,26 @@ them in turn: .. note:: - pytest by default escapes any non-ascii characters used in unicode strings - for the parametrization because it has several downsides. - If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your ``pytest.ini``: - - .. code-block:: ini - - [pytest] - disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True - - Keep in mind however that this might cause unwanted side effects and - even bugs depending on the OS used and plugins currently installed, so use it at your own risk. + 1. Paramater values are passed as-is to tests, and if you mutate them, + the mutations will be reflected in subsequent test case calls. + + Specifically, pytest doesn't do any copying of the values, since that would + put constraints on the possible parametrizable values, cause unexpected behaviour + due to broken copy/deepcopy, degrade performance, etc. + + 2. pytest by default escapes any non-ascii characters used in unicode strings + for the parametrization because it has several downsides. + If however you would like to use unicode strings in parametrization + and see them in the terminal as is (non-escaped), use this option + in your ``pytest.ini``: + + .. code-block:: ini + + [pytest] + disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True + + Keep in mind however that this might cause unwanted side effects and + even bugs depending on the OS used and plugins currently installed, so use it at your own risk. As designed in this example, only one pair of input/output values fails From a2b083843abd6576c3e1118a412075a2b85ff342 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sun, 19 Jul 2020 23:27:32 +0300 Subject: [PATCH 2/7] doc: minor typo; pep8 2nd original note --- doc/en/parametrize.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index 5e7e2ae63c6..8b18cf3b90b 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -81,26 +81,27 @@ them in turn: .. note:: - 1. Paramater values are passed as-is to tests, and if you mutate them, + 1. Parameter values are passed as-is to tests, and if you mutate them, the mutations will be reflected in subsequent test case calls. - + Specifically, pytest doesn't do any copying of the values, since that would put constraints on the possible parametrizable values, cause unexpected behaviour due to broken copy/deepcopy, degrade performance, etc. - + 2. pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. If however you would like to use unicode strings in parametrization and see them in the terminal as is (non-escaped), use this option in your ``pytest.ini``: - + .. code-block:: ini - + [pytest] disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True - + Keep in mind however that this might cause unwanted side effects and - even bugs depending on the OS used and plugins currently installed, so use it at your own risk. + even bugs depending on the OS used and plugins currently installed, + so use it at your own risk. As designed in this example, only one pair of input/output values fails From 625aa5cce47620a9b9a4cc4cdffcbfdacc1eb6fd Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 20 Jul 2020 12:54:28 +0300 Subject: [PATCH 3/7] doc: drop explaination why parametrized no copy --- doc/en/parametrize.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index 8b18cf3b90b..72de91982dd 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -81,13 +81,9 @@ them in turn: .. note:: - 1. Parameter values are passed as-is to tests, and if you mutate them, + 1. Parameter values are passed as-is to tests (no copy whatsoever), so if you mutate them, the mutations will be reflected in subsequent test case calls. - Specifically, pytest doesn't do any copying of the values, since that would - put constraints on the possible parametrizable values, cause unexpected behaviour - due to broken copy/deepcopy, degrade performance, etc. - 2. pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. If however you would like to use unicode strings in parametrization From c049831a63851d1a1e523a09608c398dec8be0b1 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 20 Jul 2020 13:40:18 +0300 Subject: [PATCH 4/7] doc: split in separate notes mutation & unicode --- doc/en/parametrize.rst | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index 72de91982dd..2fcb36b5ebf 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -81,23 +81,25 @@ them in turn: .. note:: - 1. Parameter values are passed as-is to tests (no copy whatsoever), so if you mutate them, - the mutations will be reflected in subsequent test case calls. + Parameter values are passed as-is to tests (no copy whatsoever), so if you mutate them, + the mutations will be reflected in subsequent test case calls. - 2. pytest by default escapes any non-ascii characters used in unicode strings - for the parametrization because it has several downsides. - If however you would like to use unicode strings in parametrization - and see them in the terminal as is (non-escaped), use this option - in your ``pytest.ini``: +.. note:: + + pytest by default escapes any non-ascii characters used in unicode strings + for the parametrization because it has several downsides. + If however you would like to use unicode strings in parametrization + and see them in the terminal as is (non-escaped), use this option + in your ``pytest.ini``: - .. code-block:: ini + .. code-block:: ini - [pytest] - disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True + [pytest] + disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True - Keep in mind however that this might cause unwanted side effects and - even bugs depending on the OS used and plugins currently installed, - so use it at your own risk. + Keep in mind however that this might cause unwanted side effects and + even bugs depending on the OS used and plugins currently installed, + so use it at your own risk. As designed in this example, only one pair of input/output values fails From b676882bf03853f6eb4a1d179c6a4c987de300fb Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 20 Jul 2020 13:43:44 +0300 Subject: [PATCH 5/7] doc: @bluetech's example in mutations note --- doc/en/parametrize.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index 2fcb36b5ebf..d3c2ff6cbcd 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -81,7 +81,8 @@ them in turn: .. note:: - Parameter values are passed as-is to tests (no copy whatsoever), so if you mutate them, + Parameter values are passed as-is to tests (no copy whatsoever). + For example, if you pass a list or a dict as a parameter value, and mutate it, the mutations will be reflected in subsequent test case calls. .. note:: From 07ac0ab203d5ac5b2190bfe0471f0fb8c997acab Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 20 Jul 2020 13:49:01 +0300 Subject: [PATCH 6/7] =?UTF-8?q?doc:=20split=20example=20=C2=A7=20in=20muta?= =?UTF-8?q?tion=20note?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/en/parametrize.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index d3c2ff6cbcd..f125f57b8ce 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -82,8 +82,10 @@ them in turn: .. note:: Parameter values are passed as-is to tests (no copy whatsoever). - For example, if you pass a list or a dict as a parameter value, and mutate it, - the mutations will be reflected in subsequent test case calls. + + For example, if you pass a list or a dict as a parameter value, and + the test case code mutates it, the mutations will be reflected in subsequent + test case calls. .. note:: From f55603131dca8db59a86d0b6672c9062afccc429 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 20 Jul 2020 14:49:29 +0300 Subject: [PATCH 7/7] Update doc/en/parametrize.rst --- doc/en/parametrize.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/parametrize.rst b/doc/en/parametrize.rst index f125f57b8ce..9e531ddd45d 100644 --- a/doc/en/parametrize.rst +++ b/doc/en/parametrize.rst @@ -83,7 +83,7 @@ them in turn: Parameter values are passed as-is to tests (no copy whatsoever). - For example, if you pass a list or a dict as a parameter value, and + For example, if you pass a list or a dict as a parameter value, and the test case code mutates it, the mutations will be reflected in subsequent test case calls.