From c081c5ee23200efbad96f20b766f2521272e96f6 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 18 Jan 2017 14:39:47 +0100 Subject: [PATCH 1/5] add example scripts for issue #519 --- testing/example_scripts/issue_519.py | 34 ++++++++++++++++++++++++++++ tox.ini | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 testing/example_scripts/issue_519.py diff --git a/testing/example_scripts/issue_519.py b/testing/example_scripts/issue_519.py new file mode 100644 index 00000000000..08a9e17d7c7 --- /dev/null +++ b/testing/example_scripts/issue_519.py @@ -0,0 +1,34 @@ + +import pytest +import pprint +def pytest_generate_tests(metafunc): + if 'arg1' in metafunc.fixturenames: + metafunc.parametrize("arg1", [ 'arg1v1', 'arg1v2' ], scope='module') + + if 'arg2' in metafunc.fixturenames: + metafunc.parametrize("arg2", [ 'arg2v1', 'arg2v2' ], scope='function') + +@pytest.fixture(scope='session') +def checked_order(): + order = [] + + yield order + pprint.pprint(order) + assert order == [] + + +@pytest.yield_fixture(scope='module') +def fix1(request, arg1, checked_order): + checked_order.append((request.node.name, 'fix1', arg1)) + yield 'fix1-' + arg1 + +@pytest.yield_fixture(scope='function') +def fix2(request, fix1, arg2, checked_order): + checked_order.append((request.node.name, 'fix2', arg2)) + yield 'fix2-' + arg2 + fix1 + +def test_one(fix2): + pass + +def test_two(fix2): + pass diff --git a/tox.ini b/tox.ini index c346b5682c2..e2495af4c66 100644 --- a/tox.ini +++ b/tox.ini @@ -192,7 +192,7 @@ rsyncdirs = tox.ini pytest.py _pytest testing python_files = test_*.py *_test.py testing/*/*.py python_classes = Test Acceptance python_functions = test -norecursedirs = .tox ja .hg cx_freeze_source +norecursedirs = .tox ja .hg cx_freeze_source testing/example_scripts xfail_strict=true filterwarnings = error From ea906056fae49705e9e3c7e941eb9068131eb14e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Wed, 18 Jan 2017 14:51:29 +0100 Subject: [PATCH 2/5] add the actually expected fixtureorder for #519 --- testing/example_scripts/issue_519.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/testing/example_scripts/issue_519.py b/testing/example_scripts/issue_519.py index 08a9e17d7c7..da92e42461f 100644 --- a/testing/example_scripts/issue_519.py +++ b/testing/example_scripts/issue_519.py @@ -14,7 +14,23 @@ def checked_order(): yield order pprint.pprint(order) - assert order == [] + assert order == [ + ('testing/example_scripts/issue_519.py', 'fix1', 'arg1v1'), + ('test_one[arg1v1-arg2v1]', 'fix2', 'arg2v1'), + ('test_two[arg1v1-arg2v1]', 'fix2', 'arg2v1'), + + ('test_one[arg1v1-arg2v2]', 'fix2', 'arg2v2'), + ('test_two[arg1v1-arg2v2]', 'fix2', 'arg2v2'), + + ('testing/example_scripts/issue_519.py', 'fix1', 'arg1v2'), + ('test_one[arg1v2-arg2v1]', 'fix2', 'arg2v1'), + ('test_two[arg1v2-arg2v1]', 'fix2', 'arg2v1'), + + ('test_one[arg1v2-arg2v2]', 'fix2', 'arg2v2'), + ('test_two[arg1v2-arg2v2]', 'fix2', 'arg2v2'), + ] + + @pytest.yield_fixture(scope='module') From 3ac2ae3c8caab9c7338878e9825ea2f383ca9265 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 15 Jun 2018 18:13:45 +0200 Subject: [PATCH 3/5] black --- testing/example_scripts/issue_519.py | 64 +++++++++++++++------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/testing/example_scripts/issue_519.py b/testing/example_scripts/issue_519.py index da92e42461f..d8b28521d43 100644 --- a/testing/example_scripts/issue_519.py +++ b/testing/example_scripts/issue_519.py @@ -1,50 +1,54 @@ import pytest import pprint + + def pytest_generate_tests(metafunc): - if 'arg1' in metafunc.fixturenames: - metafunc.parametrize("arg1", [ 'arg1v1', 'arg1v2' ], scope='module') + if "arg1" in metafunc.fixturenames: + metafunc.parametrize("arg1", ["arg1v1", "arg1v2"], scope="module") - if 'arg2' in metafunc.fixturenames: - metafunc.parametrize("arg2", [ 'arg2v1', 'arg2v2' ], scope='function') + if "arg2" in metafunc.fixturenames: + metafunc.parametrize("arg2", ["arg2v1", "arg2v2"], scope="function") -@pytest.fixture(scope='session') + +@pytest.fixture(scope="session") def checked_order(): order = [] yield order pprint.pprint(order) - assert order == [ - ('testing/example_scripts/issue_519.py', 'fix1', 'arg1v1'), - ('test_one[arg1v1-arg2v1]', 'fix2', 'arg2v1'), - ('test_two[arg1v1-arg2v1]', 'fix2', 'arg2v1'), - - ('test_one[arg1v1-arg2v2]', 'fix2', 'arg2v2'), - ('test_two[arg1v1-arg2v2]', 'fix2', 'arg2v2'), - - ('testing/example_scripts/issue_519.py', 'fix1', 'arg1v2'), - ('test_one[arg1v2-arg2v1]', 'fix2', 'arg2v1'), - ('test_two[arg1v2-arg2v1]', 'fix2', 'arg2v1'), - - ('test_one[arg1v2-arg2v2]', 'fix2', 'arg2v2'), - ('test_two[arg1v2-arg2v2]', 'fix2', 'arg2v2'), - ] - - - - -@pytest.yield_fixture(scope='module') + assert ( + order + == [ + ("testing/example_scripts/issue_519.py", "fix1", "arg1v1"), + ("test_one[arg1v1-arg2v1]", "fix2", "arg2v1"), + ("test_two[arg1v1-arg2v1]", "fix2", "arg2v1"), + ("test_one[arg1v1-arg2v2]", "fix2", "arg2v2"), + ("test_two[arg1v1-arg2v2]", "fix2", "arg2v2"), + ("testing/example_scripts/issue_519.py", "fix1", "arg1v2"), + ("test_one[arg1v2-arg2v1]", "fix2", "arg2v1"), + ("test_two[arg1v2-arg2v1]", "fix2", "arg2v1"), + ("test_one[arg1v2-arg2v2]", "fix2", "arg2v2"), + ("test_two[arg1v2-arg2v2]", "fix2", "arg2v2"), + ] + ) + + +@pytest.yield_fixture(scope="module") def fix1(request, arg1, checked_order): - checked_order.append((request.node.name, 'fix1', arg1)) - yield 'fix1-' + arg1 + checked_order.append((request.node.name, "fix1", arg1)) + yield "fix1-" + arg1 -@pytest.yield_fixture(scope='function') + +@pytest.yield_fixture(scope="function") def fix2(request, fix1, arg2, checked_order): - checked_order.append((request.node.name, 'fix2', arg2)) - yield 'fix2-' + arg2 + fix1 + checked_order.append((request.node.name, "fix2", arg2)) + yield "fix2-" + arg2 + fix1 + def test_one(fix2): pass + def test_two(fix2): pass From 99402cf1c05720ee2ab8465262c7da8e412b6c5e Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 15 Jun 2018 20:02:01 +0200 Subject: [PATCH 4/5] add a readme to the example scripts --- testing/example_scripts/README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 testing/example_scripts/README.rst diff --git a/testing/example_scripts/README.rst b/testing/example_scripts/README.rst new file mode 100644 index 00000000000..26ea73dd56f --- /dev/null +++ b/testing/example_scripts/README.rst @@ -0,0 +1,8 @@ +Example test scripts +===================== + + +the files in this folder are not direct tests, but rather example testsutes that demonstrate certain issues/behaviours + +in future we will move part of the content of the acceptance tests here in order to have directly testable code instead of writing out things and then running them in nested pytest sessions/subprocesses +this will aid debugging and comprehension. From 9e32b6ae4874530acf93aab547e4e30b75f65e97 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 15 Jun 2018 15:05:00 -0300 Subject: [PATCH 5/5] Small typo and grammar fix --- testing/example_scripts/README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/testing/example_scripts/README.rst b/testing/example_scripts/README.rst index 26ea73dd56f..97d0fda5c5d 100644 --- a/testing/example_scripts/README.rst +++ b/testing/example_scripts/README.rst @@ -2,7 +2,8 @@ Example test scripts ===================== -the files in this folder are not direct tests, but rather example testsutes that demonstrate certain issues/behaviours +The files in this folder are not direct tests, but rather example test suites that demonstrate certain issues/behaviours. -in future we will move part of the content of the acceptance tests here in order to have directly testable code instead of writing out things and then running them in nested pytest sessions/subprocesses -this will aid debugging and comprehension. +In the future we will move part of the content of the acceptance tests here in order to have directly testable code instead of writing out things and then running them in nested pytest sessions/subprocesses. + +This will aid debugging and comprehension.