[Test] run behave tests with test plugins outside project root

This commit is contained in:
MinchinWeb 2021-05-16 21:14:21 -06:00
parent 3492dd291a
commit 9888d98860
3 changed files with 19 additions and 5 deletions

View file

@ -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

View file

@ -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).

View file

@ -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":