From 02cf930f1dcb1abfde71b48ea098c9e013ecd90b Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Tue, 30 Aug 2022 23:27:21 +0300 Subject: [PATCH] Fix compatibility with pytest-bdd 6 --- pyproject.toml | 4 ++-- tests/lib/given_steps.py | 14 +++++++++++--- tests/lib/then_steps.py | 4 ++-- tests/lib/when_steps.py | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 0da60d5b..1b51383f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ mkdocs = ">=1.0,<1.3" poethepoet = "*" pyproject-flake8 = "*" pytest = ">=6.2" -pytest-bdd = ">=4.0.1,<6.0" +pytest-bdd = ">=4.0.1,<7.0" pytest-clarity = "*" pytest-xdist = ">=2.5.0" requests = "*" @@ -168,7 +168,7 @@ isolated_build = True [testenv] deps = pytest >= 6.2 - pytest-bdd >=4.0.1,<6.0 + pytest-bdd >=4.0.1,<7.0 pytest-xdist >=2.5.0 toml >=0.10 diff --git a/tests/lib/given_steps.py b/tests/lib/given_steps.py index 5ee88ab7..04461e95 100644 --- a/tests/lib/given_steps.py +++ b/tests/lib/given_steps.py @@ -13,6 +13,7 @@ from xml.etree import ElementTree from pytest_bdd import given from pytest_bdd.parsers import parse +from pytest_bdd.steps import inject_fixture from jrnl import __version__ from jrnl.time import __get_pdt_calendar @@ -77,8 +78,13 @@ def we_have_type_of_keyring(keyring_type): @given(parse('we use the config "{config_file}"'), target_fixture="config_path") +def we_use_the_config(request, config_file, temp_dir, working_dir): + inject_fixture(request, "config_file", config_file) + return we_use_no_config(request, temp_dir, working_dir) + + @given(parse("we use no config"), target_fixture="config_path") -def we_use_the_config(request, temp_dir, working_dir): +def we_use_no_config(request, temp_dir, working_dir): config_file = get_fixture(request, "config_file") # Move into temp dir as cwd @@ -113,13 +119,15 @@ def we_use_the_config(request, temp_dir, working_dir): @given(parse('the config "{config_file}" exists'), target_fixture="config_path") -def config_exists(config_file, temp_dir, working_dir): +def config_exists(request, config_file, temp_dir, working_dir): config_source = os.path.join(working_dir, "data", "configs", config_file) config_dest = os.path.join(temp_dir.name, config_file) shutil.copy2(config_source, config_dest) + inject_fixture(request, "config_file", config_file) + return config_dest -@given(parse('we use the password "{password}" if prompted')) +@given(parse('we use the password "{password}" if prompted'), target_fixture="password") def use_password_forever(password): return password diff --git a/tests/lib/then_steps.py b/tests/lib/then_steps.py index 28bc41cf..319e053d 100644 --- a/tests/lib/then_steps.py +++ b/tests/lib/then_steps.py @@ -127,6 +127,8 @@ def default_journal_location(journal_file, journal_dir, config_on_disk, temp_dir assert os.path.samefile(default_journal_path, expected_journal_path) +@then(parse('the config {should_or_should_not} contain "{some_yaml}"')) +@then(parse("the config {should_or_should_not} contain\n{some_yaml}")) @then( parse( 'the config for journal "{journal_name}" {should_or_should_not} contain "{some_yaml}"' @@ -137,8 +139,6 @@ def default_journal_location(journal_file, journal_dir, config_on_disk, temp_dir 'the config for journal "{journal_name}" {should_or_should_not} contain\n{some_yaml}' ) ) -@then(parse('the config {should_or_should_not} contain "{some_yaml}"')) -@then(parse("the config {should_or_should_not} contain\n{some_yaml}")) def config_var_on_disk(config_on_disk, journal_name, should_or_should_not, some_yaml): we_should = parse_should_or_should_not(should_or_should_not) diff --git a/tests/lib/when_steps.py b/tests/lib/when_steps.py index 920d66d4..df0b3f6a 100644 --- a/tests/lib/when_steps.py +++ b/tests/lib/when_steps.py @@ -7,6 +7,7 @@ from contextlib import ExitStack from pytest_bdd import when from pytest_bdd.parsers import parse from pytest_bdd.parsers import re +from pytest_bdd.steps import inject_fixture from jrnl.cli import cli @@ -29,7 +30,21 @@ all_input = '("(?P[^"]*)")' @when(parse('we run "jrnl {command}" and {input_method}\n{all_input}')) @when(re(f'we run "jrnl ?{command}" and {input_method} {all_input}')) +def we_run_jrnl_with_all_args( + request, command, input_method, all_input, cli_run, capsys, keyring +): + inject_fixture(request, "command", command) + inject_fixture(request, "input_method", input_method) + inject_fixture(request, "all_input", all_input) + return we_run_jrnl(cli_run, capsys, keyring) + + @when(parse('we run "jrnl {command}"')) +def we_run_jrnl_with_cmd(request, command, cli_run, capsys, keyring): + inject_fixture(request, "command", command) + return we_run_jrnl(cli_run, capsys, keyring) + + @when('we run "jrnl"') def we_run_jrnl(cli_run, capsys, keyring): from keyring import set_keyring