Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metadata field for custom tests #194

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
4 changes: 4 additions & 0 deletions docs/writing_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/pytest_workflow/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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):
Expand All @@ -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", {})),
Expand Down
4 changes: 4 additions & 0 deletions src/pytest_workflow/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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():
Expand Down
8 changes: 8 additions & 0 deletions tests/yamls/valid/dream_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down