Skip to content

Commit a9aa695

Browse files
authored
Merge pull request #166 from LUMC/release_2.0.0
Release 2.0.0
2 parents e1bfc76 + 2366451 commit a9aa695

38 files changed

+915
-350
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
python-version:
17-
- "3.6"
17+
- "3.7"
1818
steps:
1919
- uses: actions/[email protected]
2020
- name: Set up Python ${{ matrix.python-version }}
@@ -26,7 +26,6 @@ jobs:
2626
- name: Lint
2727
run: tox -e lint
2828
docs:
29-
needs: lint
3029
runs-on: ubuntu-latest
3130
steps:
3231
- uses: actions/[email protected]
@@ -43,12 +42,11 @@ jobs:
4342
strategy:
4443
matrix:
4544
python-version:
46-
- "3.6"
4745
- "3.7"
4846
- "3.8"
4947
- "3.9"
5048
- "3.10"
51-
needs: lint
49+
- "3.11"
5250
steps:
5351
- uses: actions/[email protected]
5452
- name: Set up Python ${{ matrix.python-version }}
@@ -60,7 +58,6 @@ jobs:
6058
- name: Run tests
6159
run: tox -e py3
6260
- name: Upload coverage report
63-
if: ${{ matrix.python-version == 3.6 }} # Only upload coverage once
6461
uses: codecov/codecov-action@v1
6562

6663
test-functional:

HISTORY.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 2.0.0
11+
---------------------------
12+
This major release greatly cleans up the output of pytest-workflow in case of
13+
an error as well as providing the stderr and stdout last bytes for debugging
14+
purposes. When the exit code test fails all other tests from the workflow
15+
are skipped.
16+
17+
+ Python 3.6 is no longer supported. It has been removed from github actions,
18+
as such we can no longer guarantee that pytest-workflow works properly
19+
with python 3.6.
20+
+ Fix an issue where symlinks in git repositories could not be properly copied.
21+
+ Added an optional encoding key for files, stdout and stderr so the file can
22+
be opened with the proper encoding.
23+
+ Make content tests more efficient by reading each file only once instead of
24+
twice when there are both strings and regexes to check for.
25+
+ When the ``--git-aware`` flag is used a submodule check is performed in order
26+
to assert that all submodules are properly checked out. This prevents
27+
unclear copying errors.
28+
+ Tests are now skipped if the workflow does not exit with the desired exit
29+
code, except for the exit code tests, to reduce visual clutter when reporting
30+
failing tests.
31+
+ Tests for checking file content are now skipped when the file does not exist
32+
in order to reduce visual clutter when reporting failing tests.
33+
+ Test and support for Python 3.11.
34+
+ Add ``--stderr-bytes`` or ``--sb`` option to change the maximum
35+
number of bytes to display for the stderr and stdout on
36+
command failure.
37+
+ Add stderr and stdout to be displayed on command failure
38+
+ Document using ``pytest.ini`` as a way of setting specific per repository
39+
settings for pytest-workflow.
40+
+ Add tests for nextflow.
41+
+ Document the use of environment variables with pytest-workflow.
42+
+ A minimum of pytest 7.0.0 is now a requirement for pytest-workflow.
43+
This fixes the deprecation warnings that started on the release of pytest
44+
7.0.0.
45+
+ Throw a more descriptive error when a file copied with the --git-aware flag
46+
is not present on the filesystem anymore.
47+
+ Document pytest flags ``-k`` and ``-m`` are not supported.
48+
1049
version 1.6.0
1150
---------------------------
1251
+ Add a ``--git-aware`` or ``--ga`` option to only copy copy files listed by

README.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ pytest-workflow
3434

3535
pytest-workflow is a workflow-system agnostic testing framework that aims
3636
to make pipeline/workflow testing easy by using YAML files for the test
37-
configuration. Whether you write your pipelines in WDL, snakemake, bash or
38-
any other workflow framework, pytest-workflow makes testing easy.
37+
configuration. Whether you write your pipelines in WDL, snakemake, nextflow,
38+
bash or any other workflow framework, pytest-workflow makes testing easy.
3939
pytest-workflow is build on top of the pytest test framework.
4040

41-
For our complete documentation checkout our
41+
For our complete documentation and examples checkout our
4242
`readthedocs page <https://pytest-workflow.readthedocs.io/>`_.
4343

4444

4545
Installation
4646
============
47-
Pytest-workflow requires Python 3.6 or higher. It is tested on Python 3.6, 3.7,
48-
3.8, 3.9 and 3.10. Python 2 is not supported.
47+
Pytest-workflow requires Python 3.7 or higher. It is tested on Python 3.7,
48+
3.8, 3.9, 3.10 and 3.11.
4949

5050
- Make sure your virtual environment is activated.
5151
- Install using pip ``pip install pytest-workflow``
@@ -103,6 +103,7 @@ predefined tests as well as custom tests are possible.
103103
must_not_contain: # A list of strings that should NOT be in the file (optional)
104104
- "Cock a doodle doo"
105105
md5sum: e583af1f8b00b53cda87ae9ead880224 # Md5sum of the file (optional)
106+
encoding: UTF-8 # Encoding for the text file (optional). Defaults to system locale.
106107
107108
- name: simple echo # A second workflow. Notice the starting `-` which means
108109
command: "echo moo" # that workflow items are in a list. You can add as much workflows as you want
@@ -114,6 +115,7 @@ predefined tests as well as custom tests are possible.
114115
- "moo"
115116
must_not_contain: # List of strings that should NOT be in stout (optional)
116117
- "Cock a doodle doo"
118+
encoding: ASCII # Encoding for stdout (optional). Defaults to system locale.
117119
118120
- name: mission impossible # Also failing workflows can be tested
119121
tags: # A list of tags that can be used to select which test
@@ -130,6 +132,7 @@ predefined tests as well as custom tests are possible.
130132
- "BSOD error, please contact the IT crowd"
131133
must_not_contain: # A list of strings which should NOT be in stderr (optional)
132134
- "Mission accomplished!"
135+
encoding: UTF-16 # Encoding for stderr (optional). Defaults to system locale.
133136
134137
- name: regex tests
135138
command: echo Hello, world
@@ -143,7 +146,7 @@ predefined tests as well as custom tests are possible.
143146
- '^Hello .*' # Complex regexes will break yaml if double quotes are used
144147
145148
For more information on how Python parses regular expressions, see the `Python
146-
documentation <https://docs.python.org/3.6/library/re.html>`_.
149+
documentation <https://docs.python.org/3/library/re.html>`_.
147150

148151
Documentation for more advanced use cases including the custom tests can be
149152
found on our `readthedocs page <https://pytest-workflow.readthedocs.io/>`_.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#
6565
# This is also used if you do content translation via gettext catalogs.
6666
# Usually you set "language" from the command line for these cases.
67-
language = None
67+
language = "en"
6868

6969
# List of patterns, relative to source directory, that match files and
7070
# directories to ignore when looking for source files.

docs/examples.rst

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ information on the localization of output files as well as options to modify
7979
the running of miniwdl from the environment.
8080

8181
Miniwdl will localize all the output files to an ``output_links`` directory
82-
inside the test output directory. If you have a workflow with the output:
82+
inside the test output directory. If you have a workflow with the output::
8383

84-
.. code-block::
85-
86-
output {
87-
File moo_file = moo_task.out
88-
Array[File] stats = moo_task.stats_files
89-
}
84+
output {
85+
File moo_file = moo_task.out
86+
Array[File] stats = moo_task.stats_files
87+
}
9088

9189
Inside the ``out`` directory the directories ``moo_file`` and
9290
``stats`` will be created. Inside these directories will be the produced files.
@@ -109,3 +107,96 @@ The following yaml file tests a WDL pipeline run with miniwdl.
109107
110108
Please note that the trailing slash in ``-d test-output/`` is important. It
111109
will ensure the files end up in the ``test-output`` directory.
110+
111+
Nextflow example
112+
-----------------
113+
114+
With nextflow each process is run in a unique directory where the output files will
115+
also be stored. Nextflow can output a copy of the output files to a separate workflow-outputs
116+
directory. This can be achieved by defining a ``publishDir`` in the process. Through ``params.outdir``
117+
it is possible to define the output directory when running the code.
118+
119+
An example code defining a ``publishDir`` is listed below. ::
120+
121+
process Hello {
122+
publishDir = [
123+
path: { "${params.outdir}/hello"}
124+
]
125+
126+
output:
127+
path "HelloWorld.txt"
128+
script:
129+
"""
130+
echo "Hello World!" > HelloWorld.txt
131+
"""
132+
}
133+
134+
workflow {
135+
Hello
136+
}
137+
138+
To run the code listed above the following command can be used in which ``examplecode.nf`` is the code listed above:
139+
140+
.. code-block:: bash
141+
142+
nextflow run examplecode.nf --outdir test-output
143+
144+
``publishDir`` will make it so that all the output files of the process are copied to the given directory.
145+
``--outdir`` is used to define the path the output files will go to. In this case ``HelloWorld.txt`` will
146+
be copied to the directory called ``test-output/hello``.
147+
148+
An example yaml file that could be used to test the nextflow pipeline from ``examplecode.nf`` is listed
149+
below.
150+
151+
.. code-block:: yaml
152+
153+
- name: My pipeline
154+
command: nextflow run examplecode.nf --outdir test-output
155+
files:
156+
- path: "test-output/hello/HelloWorld.txt"
157+
158+
Bash example
159+
------------
160+
161+
The following is an example of a Bash file that can run directly as a script, or sourced to test each function separately:
162+
163+
.. code-block:: bash
164+
165+
#!/usr/bin/env bash
166+
167+
function say_hello() {
168+
local name="$1"
169+
echo "Hello, ${name}!"
170+
}
171+
172+
function main() {
173+
say_hello world
174+
}
175+
176+
# Only execute main when this file is run as a script
177+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
178+
main
179+
fi
180+
181+
Save the bash file as ``script.sh``, and test it with the following pytest-workflow configuration:
182+
183+
184+
.. code-block:: yaml
185+
186+
- name: test bash script
187+
command: bash script.sh
188+
stdout:
189+
contains:
190+
- "Hello, world!"
191+
192+
- name: test bash function
193+
command: >
194+
bash -c "
195+
source script.sh;
196+
say_hello pytest-workflow
197+
"
198+
stdout:
199+
contains:
200+
- "Hello, pytest-workflow!"
201+
must_not_contain:
202+
- "Hello, world!"

docs/installation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
Installation
33
============
44

5-
Pytest-workflow is tested on python 3.6, 3.7, 3.8, 3.9 and 3.10. Python 2 is not
6-
supported.
5+
Pytest-workflow is tested on python 3.7, 3.8, 3.9, 3.10 and 3.11.
76

87
In a virtual environment
98
------------------------

docs/known_issues.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Known issues
2121
``contains_regex`` and ``must_not_contain_regex``, since this collides with
2222
Python's usage of the same character to escape special characters in strings.
2323
Please see the `Python documentation on regular expressions
24-
<https://docs.python.org/3.6/library/re.html>`_ for details.
24+
<https://docs.python.org/3/library/re.html>`_ for details.

docs/running_pytest_workflow.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ Specific pytest options for pytest workflow
2626
:func: __pytest_workflow_cli
2727
:prog: pytest
2828

29+
Setting specific per-project settings using pytest.ini
30+
-----------------------------------------------------------------
31+
pytest can be configured `using a pytest.ini file
32+
<https://docs.pytest.org/en/7.1.x/reference/customize.html#pytest-ini>`_.
33+
This mechanic can be used to set specific settings in each repository
34+
where pytest workflow is used.
35+
36+
For example a pytest.ini with the following contents::
37+
38+
[pytest]
39+
addopts = --git-aware
40+
41+
Can be used in a git repository with a workflow.
42+
2943
Temporary directory cleanup and creation
3044
----------------------------------------
3145

@@ -115,3 +129,9 @@ Internally names and tags are handled the same so if the following tests:
115129
- hello
116130
117131
are run with ``pytest --tag hello`` then both ``hello`` and ``hello2`` are run.
132+
133+
.. note::
134+
135+
The pytest flags ``-k`` and ``-m`` are not supported by pytest-workflow.
136+
Rational for this design decision can be `found within GitHub issue #155
137+
<https://github.com/LUMC/pytest-workflow/issues/155#issuecomment-1334911457>`_.

docs/writing_tests.rst

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Test options
4040
must_not_contain: # A list of strings that should NOT be in the file (optional)
4141
- "Cock a doodle doo"
4242
md5sum: e583af1f8b00b53cda87ae9ead880224 # Md5sum of the file (optional)
43+
encoding: UTF-8 # Encoding for the text file (optional). Defaults to system locale.
4344
4445
- name: simple echo # A second workflow. Notice the starting `-` which means
4546
command: "echo moo" # that workflow items are in a list. You can add as much workflows as you want
@@ -51,6 +52,7 @@ Test options
5152
- "moo"
5253
must_not_contain: # List of strings that should NOT be in stout (optional)
5354
- "Cock a doodle doo"
55+
encoding: ASCII # Encoding for stdout (optional). Defaults to system locale.
5456
5557
- name: mission impossible # Also failing workflows can be tested
5658
tags: # A list of tags that can be used to select which test
@@ -60,13 +62,14 @@ Test options
6062
files:
6163
- path: "fail.log" # Multiple files can be tested for each workflow
6264
- path: "TomCruise.txt.gz" # Gzipped files can also be searched, provided their extension is '.gz'
63-
contains:
65+
contains:
6466
- "starring"
6567
stderr: # Options for testing stderr (optional)
6668
contains: # A list of strings which should be in stderr (optional)
6769
- "BSOD error, please contact the IT crowd"
6870
must_not_contain: # A list of strings which should NOT be in stderr (optional)
6971
- "Mission accomplished!"
72+
encoding: UTF-16 # Encoding for stderr (optional). Defaults to system locale.
7073
7174
- name: regex tests
7275
command: echo Hello, world
@@ -83,13 +86,40 @@ Test options
8386
The above YAML file contains all the possible options for a workflow test.
8487

8588
Please see the `Python documentation on regular expressions
86-
<https://docs.python.org/3.6/library/re.html>`_ to see how Python handles escape
89+
<https://docs.python.org/3/library/re.html>`_ to see how Python handles escape
8790
sequences.
8891

8992
.. note::
9093
Workflow names must be unique. Pytest workflow will crash when multiple
9194
workflows have the same name, even if they are in different files.
9295

96+
Environment variables
97+
----------------------
98+
Pytest-workflow runs tests in the same environment as in which the pytest
99+
executable was started. This means programs started in tests can use
100+
environnment variables. However, environment variables inside the command
101+
section itself are quoted by pytest-workflow using
102+
`shlex.quote <https://docs.python.org/3/library/shlex.html#shlex.quote>`_.
103+
See the examples below:
104+
105+
.. code-block:: YAML
106+
107+
- name: Try to use an environment variable
108+
command: echo $MY_VAR
109+
# Output will be literally "$MY_VAR"
110+
111+
- name: Circumenvent shlex quoting by explicitly starting the command in a shell.
112+
command: bash -c 'echo $MY_VAR'
113+
# Output will be the content of $MY_VAR
114+
115+
- name: Use a program that checks an environment variable
116+
command: singularity run my_container.sif
117+
# Correctly uses "SINGULARITY_" prefixed variables
118+
119+
If you want to use shell scripting features such as environment
120+
variables inside ``command``, you need to explicitly set the shell as shown
121+
above.
122+
93123
Writing custom tests
94124
--------------------
95125

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pyyaml
2-
pytest>=5.4.0
2+
pytest>=7.0.0
33
jsonschema

0 commit comments

Comments
 (0)