diff --git a/HISTORY.rst b/HISTORY.rst index e1f5c312..a985396e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,6 +8,11 @@ Changelog .. This document is user facing. Please word the changes in such a way .. that users understand how the changes affect the new version. +version 2.2.0-dev +--------------------------- ++ Add an optional ``metadata`` field to the test yaml schema that can be used + for custom tests. + version 2.1.0 --------------------------- + Python version 3.7 support is dropped because it is deprecated. Python @@ -50,9 +55,9 @@ are skipped. + Tests for checking file content are now skipped when the file does not exist in order to reduce visual clutter when reporting failing tests. + Test and support for Python 3.11. -+ Add ``--stderr-bytes`` or ``--sb`` option to change the maximum - number of bytes to display for the stderr and stdout on - command failure. ++ Add ``--stderr-bytes`` or ``--sb`` option to change the maximum + number of bytes to display for the stderr and stdout on + command failure. + Add stderr and stdout to be displayed on command failure + Document using ``pytest.ini`` as a way of setting specific per repository settings for pytest-workflow. @@ -302,4 +307,4 @@ Version 0.1.0 + Pytest-workflow now has continuous integration and coverage reporting, so we can detect regressions quickly and only publish well-tested versions. + Fully parametrized tests enabled by changing code structure. -+ Initialized pytest-workflow with option to test if files exist. ++ Initialized pytest-workflow with option to test if files exist. diff --git a/docs/writing_tests.rst b/docs/writing_tests.rst index 0a3896d1..a1d93356 100644 --- a/docs/writing_tests.rst +++ b/docs/writing_tests.rst @@ -44,6 +44,10 @@ Test options - name: simple echo # A second workflow. Notice the starting `-` which means command: "echo moo" # that workflow items are in a list. You can add as much workflows as you want + metadata: # A list of metadata to associate with the test and can be used to, for example, + - "some metadata" # parameterize custom workflows. Each metadata entry can be a simple string + - structured_metadata: # or a complex structured object + key: value files: - path: "moo.txt" should_exist: false # Whether a file should be there or not. (optional, if not given defaults to true) diff --git a/src/pytest_workflow/schema.py b/src/pytest_workflow/schema.py index 499dd416..1caa75e7 100644 --- a/src/pytest_workflow/schema.py +++ b/src/pytest_workflow/schema.py @@ -161,6 +161,7 @@ class WorkflowTest(object): def __init__(self, name: str, command: str, tags: Optional[List[str]], + metadata: Optional[List] = None, exit_code: int = DEFAULT_EXIT_CODE, stdout: ContentTest = ContentTest(), stderr: ContentTest = ContentTest(), @@ -181,6 +182,7 @@ def __init__(self, name: str, command: str, self.stderr = stderr self.files = files or [] self.tags = tags or [] + self.metadata = metadata or [] @classmethod def from_schema(cls, schema: dict): @@ -192,6 +194,7 @@ def from_schema(cls, schema: dict): name=schema["name"], command=schema["command"], tags=schema.get("tags"), + metadata=schema.get("metadata"), exit_code=schema.get("exit_code", DEFAULT_EXIT_CODE), stdout=ContentTest(**schema.get("stdout", {})), stderr=ContentTest(**schema.get("stderr", {})), diff --git a/src/pytest_workflow/schema/schema.json b/src/pytest_workflow/schema/schema.json index 718b6c25..e3105ecc 100644 --- a/src/pytest_workflow/schema/schema.json +++ b/src/pytest_workflow/schema/schema.json @@ -31,6 +31,10 @@ "type": "string" } }, + "metadata": { + "description": "Metadata for the workflow test", + "type": "array" + }, "command": { "description": "The command that is run for the workflow", "type": "string", diff --git a/tests/test_schema.py b/tests/test_schema.py index 8defda21..d70f9732 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -20,14 +20,15 @@ from pathlib import Path import jsonschema - import pytest - -from pytest_workflow.schema import ContentTest, FileTest, WorkflowTest, \ - validate_schema, workflow_tests_from_schema - import yaml - +from pytest_workflow.schema import ( + ContentTest, + FileTest, + WorkflowTest, + validate_schema, + workflow_tests_from_schema, +) VALID_YAML_DIR = Path(__file__).parent / "yamls" / "valid" VALID_YAMLS = os.listdir(VALID_YAML_DIR) @@ -50,6 +51,10 @@ def test_workflowtest(): assert tests[0].stdout.contains == ["bla"] assert tests[0].exit_code == 127 assert tests[0].tags == ["simple", "use_echo"] + assert tests[0].metadata == [ + "simple item", + {"complex_item": {"key": "value", "list_field": ["item1", "item2"]}, "key1": "value1"} + ] def test_workflowtest_regex(): diff --git a/tests/yamls/valid/dream_file.yaml b/tests/yamls/valid/dream_file.yaml index d5096d69..3ba1f3c7 100644 --- a/tests/yamls/valid/dream_file.yaml +++ b/tests/yamls/valid/dream_file.yaml @@ -26,6 +26,14 @@ encoding: UTF8 exit_code: 127 command: "the one string" + metadata: + - "simple item" + - complex_item: + key: value + list_field: + - item1 + - item2 + key1: value1 - name: other test command: "cowsay moo" files: