Skip to content
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
repos:
- repo: https://github.com/psf/black
rev: 24.1.1
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 26.1.0
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.3.0
hooks:
- id: flake8
exclude: docs
Expand Down
54 changes: 18 additions & 36 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,34 @@


def test_metadata(pytester):
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
for k in ['Python', 'Platform', 'Packages']:
assert k in metadata
assert 'JENKINS_URL' not in metadata
"""
)
""")
result = pytester.runpytest()
assert result.ret == 0


def test_environment_variables(pytester, monkeypatch):
monkeypatch.setenv("JENKINS_URL", "foo")
monkeypatch.setenv("GIT_COMMIT", "bar")
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('JENKINS_URL') == 'foo'
assert metadata.get('GIT_COMMIT') == 'bar'
"""
)
""")
result = pytester.runpytest()
assert result.ret == 0


def test_additional_metadata(pytester):
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('Dave') == 'Hunt'
assert metadata.get('Jim') == 'Bob'
"""
)
""")
result = pytester.runpytest(
"--metadata", "Dave", "Hunt", "--metadata", "Jim", "Bob"
)
Expand All @@ -50,16 +44,14 @@ def test_pass(metadata):

@pytest.mark.parametrize("junit_format", ["xunit1", "xunit2"])
def test_junit_integration(pytester, junit_format):
pytester.makepyfile(
"""
pytester.makepyfile("""
import pytest

pytestmark = pytest.mark.usefixtures('include_metadata_in_junit_xml')

def test_pass():
pass
"""
)
""")
result = pytester.runpytest(
"--metadata",
"Daffy",
Expand All @@ -79,38 +71,32 @@ def test_pass():


def test_additional_metadata_from_json(pytester):
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('Imran') == 'Mumtaz'
"""
)
""")
result = pytester.runpytest("--metadata-from-json", '{"Imran": "Mumtaz"}')
assert result.ret == 0


def test_additional_metadata_from_json_file(pytester):
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('John') == 'Cena'
"""
)
""")
pytester.makefile(".json", temp='{"John": "Cena"}')

result = pytester.runpytest("--metadata-from-json-file", "temp.json")
assert result.ret == 0


def test_additional_metadata_using_key_values_json_str_and_file(pytester):
pytester.makepyfile(
"""
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('John') == 'Cena'
assert metadata.get('Dwayne') == 'Johnson'
assert metadata.get('Andre') == 'The Giant'
"""
)
""")
pytester.makefile(".json", temp='{"Andre": "The Giant"}')

result = pytester.runpytest(
Expand All @@ -126,20 +112,16 @@ def test_pass(metadata):


def test_metadata_hook(pytester):
pytester.makeconftest(
"""
pytester.makeconftest("""
import pytest
@pytest.hookimpl(optionalhook=True)
def pytest_metadata(metadata):
metadata['Dave'] = 'Hunt'
"""
)
pytester.makepyfile(
"""
""")
pytester.makepyfile("""
def test_pass(metadata):
assert metadata.get('Dave') == 'Hunt'
"""
)
""")
result = pytester.runpytest()
assert result.ret == 0

Expand Down