From 21245a8501b3cabc7a5bb40bf14f50a1621ddbed Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Mon, 6 Jul 2020 14:41:42 -0400 Subject: [PATCH 1/3] HACKING.rst: add pytest.param pytest gotcha --- HACKING.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/HACKING.rst b/HACKING.rst index 27a38bc3ff9..e58fd39465b 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -236,6 +236,13 @@ The following guidelines should be followed: ``util.write_file(tmpdir.join("some_file"), ...)``, you should write ``util.write_file(tmpdir.join("some_file").strpath, ...)``. + * `pytest.param`_ cannot be used. It was introduced in pytest 3.1, + which means it is not available on xenial. The more limited + mechanism it replaced was removed in pytest 4.0, so is not + available in focal or later. The only available alternative is to + write mark-requiring test instances as completely separate tests, + without utilising parameterisation. + * Variables/parameter names for ``Mock`` or ``MagicMock`` instances should start with ``m_`` to clearly distinguish them from non-mock variables @@ -302,6 +309,7 @@ The following guidelines should be followed: .. _TestPrependBaseCommands: https://github.com/canonical/cloud-init/blob/master/cloudinit/tests/test_subp.py#L9 .. _assertion introspection: https://docs.pytest.org/en/latest/assert.html .. _pytest 3.0: https://docs.pytest.org/en/latest/changelog.html#id1093 +.. _pytest.param: https://docs.pytest.org/en/latest/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions .. _autospecced: https://docs.python.org/3.8/library/unittest.mock.html#autospeccing Type Annotations From bdcfc042967637a4da18fa7f371876bbc2352347 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 8 Jul 2020 12:29:36 -0400 Subject: [PATCH 2/3] HACKING.rst: apply falcojr's suggested improvement --- HACKING.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index e58fd39465b..6bf6a3f3436 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -236,9 +236,9 @@ The following guidelines should be followed: ``util.write_file(tmpdir.join("some_file"), ...)``, you should write ``util.write_file(tmpdir.join("some_file").strpath, ...)``. - * `pytest.param`_ cannot be used. It was introduced in pytest 3.1, - which means it is not available on xenial. The more limited - mechanism it replaced was removed in pytest 4.0, so is not + * The `pytest.param`_ function cannot be used. It was introduced in + pytest 3.1, which means it is not available on xenial. The more + limited mechanism it replaced was removed in pytest 4.0, so is not available in focal or later. The only available alternative is to write mark-requiring test instances as completely separate tests, without utilising parameterisation. @@ -309,7 +309,7 @@ The following guidelines should be followed: .. _TestPrependBaseCommands: https://github.com/canonical/cloud-init/blob/master/cloudinit/tests/test_subp.py#L9 .. _assertion introspection: https://docs.pytest.org/en/latest/assert.html .. _pytest 3.0: https://docs.pytest.org/en/latest/changelog.html#id1093 -.. _pytest.param: https://docs.pytest.org/en/latest/parametrize.html#pytest-mark-parametrize-parametrizing-test-functions +.. _pytest.param: https://docs.pytest.org/en/latest/reference.html#pytest-param .. _autospecced: https://docs.python.org/3.8/library/unittest.mock.html#autospeccing Type Annotations From 8289fe00ab2c66a4d868656230d6d446bb0fb672 Mon Sep 17 00:00:00 2001 From: Daniel Watkins Date: Wed, 8 Jul 2020 12:31:09 -0400 Subject: [PATCH 3/3] Add another possible pytest.param workaround --- HACKING.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 6bf6a3f3436..60c7b5e0834 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -239,9 +239,10 @@ The following guidelines should be followed: * The `pytest.param`_ function cannot be used. It was introduced in pytest 3.1, which means it is not available on xenial. The more limited mechanism it replaced was removed in pytest 4.0, so is not - available in focal or later. The only available alternative is to - write mark-requiring test instances as completely separate tests, - without utilising parameterisation. + available in focal or later. The only available alternatives are + to write mark-requiring test instances as completely separate + tests, without utilising parameterisation, or to apply the mark to + the entire parameterized test (and therefore every test instance). * Variables/parameter names for ``Mock`` or ``MagicMock`` instances should start with ``m_`` to clearly distinguish them from non-mock