From 9888d9886004432a86ada2a8e159894a93c1b9a7 Mon Sep 17 00:00:00 2001 From: MinchinWeb Date: Sun, 16 May 2021 21:14:21 -0600 Subject: [PATCH] [Test] run behave tests with test plugins outside project root --- .github/workflows/testing_external_plugins.yaml | 8 ++++++-- docs/plugins.md | 9 ++++++++- features/environment.py | 7 +++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/testing_external_plugins.yaml b/.github/workflows/testing_external_plugins.yaml index 3dd7d156..3ae7b3ed 100644 --- a/.github/workflows/testing_external_plugins.yaml +++ b/.github/workflows/testing_external_plugins.yaml @@ -52,11 +52,15 @@ jobs: poetry install --remove-untracked poetry install poetry run python -m pip install ./tests/external_plugins_src/ + cd .. + # installed test plugins aren't recognized by "behave" if run from the + # project's root folder, but "poetry run" doesn't work on folders upstream + # from project root - name: Test with pytest if: success() || failure() - run: poetry run pytest --junitxml=reports/pytest/results.xml + run: pytest --junitxml=reports/pytest/results.xml - name: Test with behave if: success() || failure() - run: poetry run behave --no-skipped --format progress2 --junit --junit-directory reports/behave + run: behave --no-skipped --format progress2 --junit --junit-directory reports/behave jrnl/features diff --git a/docs/plugins.md b/docs/plugins.md index 7d81ec8b..c8f7cc96 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -165,10 +165,17 @@ situations other than a traditional export. They are: ## Development Tips -- editable installs (`pip install -e ...`) don't seem to play nice with +- Editable installs (`pip install -e ...`) don't seem to play nice with the namespace layout. If your plugin isn't appearing, try a non-editable install of both *jrnl* and your plugin. +- If you run *jrnl* from the main project root directory (the one that contains + *jrnl*'s source code), namespace plugins won't be recognized. This is (I + suspect) because the Python interpreter will find your *jrnl* source directory + (which doesn't contain your namespace plugins) before it find your + "site-packages" directory (i.e. installed packages, which will recognize + namespace packages). - Don't name your plugin file "testing.py" or it won't be installed (at least automatically) by pip. +- For examples, you can look to the *jrnl*'s internal importers and exporters. As well, there are some basic external examples included in *jrnl*'s git repo at `tests/external_plugins_src` (including the example code above). diff --git a/features/environment.py b/features/environment.py index 87053163..766f9576 100644 --- a/features/environment.py +++ b/features/environment.py @@ -11,6 +11,7 @@ except ImportError: CWD = os.getcwd() HERE = Path(__file__).resolve().parent +TARGET_CWD = HERE.parent # project root folder # @see https://behave.readthedocs.io/en/latest/tutorial.html#debug-on-error-in-case-of-step-failures BEHAVE_DEBUG_ON_ERROR = False @@ -22,6 +23,8 @@ def setup_debug_on_error(userdata): def before_all(context): + # always start in project root directory + os.chdir(TARGET_CWD) setup_debug_on_error(context.config.userdata) @@ -102,8 +105,8 @@ def before_scenario(context, scenario): def after_scenario(context, scenario): """After each scenario, restore all test data and remove working_dirs.""" - if os.getcwd() != CWD: - os.chdir(CWD) + if os.getcwd() != TARGET_CWD: + os.chdir(TARGET_CWD) # only clean up if debugging is off and the scenario passed if BEHAVE_DEBUG_ON_ERROR and scenario.status != "failed":