Skip to content

Commit

Permalink
Merge pull request #60 from LUMC/kwd
Browse files Browse the repository at this point in the history
add --kwd flag and notify user of directory deletion
  • Loading branch information
sndrtj committed Feb 20, 2019
2 parents 2bba68f + 622a2e5 commit 93de47c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Changelog
.. NOTE: This document is user facing. Please word the changes in such a way
.. that users understand how the changes affect the new version.
version 1.2.0
---------------------------
+ Added ``--kwd`` as alias for ``--keep-workflow-wd``. Notify the user of
deletion of temporary directories and logs.

version 1.1.0
---------------------------
+ Enabled custom tests on workflow files.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ To check the progress of a workflow while it is running you can use ``tail -f``
on the ``stdout`` or ``stderr`` file of the workflow. The locations of these
files are reported in the log as soon as a workflow is started.

For debugging pipelines using the ``--keep-workflow-wd`` flag is
For debugging pipelines using the ``--kwd`` or ``--keep-workflow-wd`` flag is
recommended. This will keep the workflow directory and logs after the test run
so it is possible to check where the pipeline crashed. The ``-v`` flag can come
in handy as well as it gives a complete overview of succeeded and failed tests.
Expand Down
4 changes: 2 additions & 2 deletions docs/running_pytest_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The workflows are run automatically. Each workflow gets its own temporary
directory to run. The ``stdout`` and ``stderr`` of the workflow command are
also saved to this directory. The temporary directories are cleaned up after
the tests are completed. If you wish to inspect the output of a failing
workflow you can use the ``--keep-workflow-wd`` flag to disable cleanup. This
will also make sure the logs of the pipeline are not deleted. The
workflow you can use the ``--kwd`` or ``--keep-workflow-wd`` flag to disable
cleanup. This will also make sure the logs of the pipeline are not deleted. The
``--keep-workflow-wd`` flag is highly recommended when debugging pipelines.

If you wish to change the temporary directory in which the workflows are run
Expand Down
5 changes: 4 additions & 1 deletion src/pytest_workflow/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

def pytest_addoption(parser: PytestParser):
parser.addoption(
"--keep-workflow-wd",
"--kwd", "--keep-workflow-wd",
action="store_true",
help="Keep temporary directories where workflows are run for "
"debugging purposes. This also triggers saving of stdout and "
Expand Down Expand Up @@ -191,6 +191,9 @@ def pytest_runtestloop(session: pytest.Session):

def pytest_sessionfinish(session: pytest.Session):
if not session.config.getoption("keep_workflow_wd"):
# The newline is needed otherwise everything looks ugly.
print("\nRemoving temporary directories and logs. Use '--kwd' or "
"'--keep-workflow-wd' to disable this behaviour.")
for tempdir in session.config.workflow_cleanup_dirs:
shutil.rmtree(str(tempdir))

Expand Down
3 changes: 3 additions & 0 deletions tests/test_temp_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def test_directory_not_kept(testdir):
working_dir = re.search(r"with command 'echo moo' in '([\w\/_-]*)'",
result.stdout.str()).group(1)
assert not Path(working_dir).exists()
assert ("Removing temporary directories and logs. Use '--kwd' or "
"'--keep-workflow-wd' to disable this behaviour."
) in result.stdout.str()


def test_basetemp_correct(testdir):
Expand Down

0 comments on commit 93de47c

Please sign in to comment.