From dc55551213a7e55fb7de7ff1d59ea9ba124f6514 Mon Sep 17 00:00:00 2001 From: Raphael Pierzina Date: Fri, 24 Jun 2016 12:08:57 +0200 Subject: [PATCH] Start proposal for parametrize with fixtures --- doc/en/parametrize_with_fixtures.rst | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 doc/en/parametrize_with_fixtures.rst diff --git a/doc/en/parametrize_with_fixtures.rst b/doc/en/parametrize_with_fixtures.rst new file mode 100644 index 000000000..06cfea5e3 --- /dev/null +++ b/doc/en/parametrize_with_fixtures.rst @@ -0,0 +1,58 @@ +========================= +Parametrize with fixtures +========================= + +Problem +------- + +As a user I have functional tests that I would like to run against various +scenarios. + +In this particular example we want to generate a new project based on a +cookiecutter template. We want to test default values but also data that +emulates user input. + +- use default values +- emulate user input + - specify 'author' + - specify 'project_slug' + - specify 'author' and 'project_slug' + +This is how a functional test could look like: + +.. code-block:: python + + import pytest + + @pytest.fixture + def default_context(): + return {'extra_context': {}} + + + @pytest.fixture(params=[ + {'author': 'alice'}, + {'project_slug': 'helloworld'}, + {'author': 'bob', 'project_slug': 'foobar'}, + ]) + def extra_context(request): + return {'extra_context': request.param} + + + @pytest.fixture(params=['default', 'extra']) + def context(request): + if request.param == 'default': + return request.getfuncargvalue('default_context') + else: + return request.getfuncargvalue('extra_context') + + + def test_generate_project(cookies, context): + """Call the cookiecutter API to generate a new project from a + template. + """ + result = cookies.bake(extra_context=context) + + assert result.exit_code == 0 + assert result.exception is None + assert result.project.isdir() +