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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
54 changes: 18 additions & 36 deletions tests/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,29 @@ def run(testdir, file_format="json", variables=None, raw=False):


def test_missing_extension(testdir, recwarn):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['foo'] == 'bar'
"""
)
""")
result = run(testdir, "")
assert result.ret == 0
assert len(recwarn) == 0


def test_no_variables(testdir):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables == {}
"""
)
""")
result = testdir.runpytest()
assert result.ret == 0


def test_unsupported_format(testdir, recwarn):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['foo'] == 'bar'
"""
)
""")
result = run(testdir, "invalid")
assert result.ret == 0
assert len(recwarn) == 1
Expand All @@ -75,12 +69,10 @@ def test(variables):


def test_variables_basic(testdir, file_format):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['foo'] == 'bar'
"""
)
""")
result = run(testdir, file_format)
assert result.ret == 0

Expand All @@ -93,37 +85,31 @@ def test_invalid_format(testdir, file_format):


def test_key_error(testdir, file_format):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['bar'] == 'foo'
"""
)
""")
result = run(testdir, file_format)
assert result.ret == 1
result.stdout.fnmatch_lines(["*KeyError: *"])


def test_multiple_variables(testdir, file_format):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['foo'] == 'bar'
assert variables['bar'] == 'foo'
"""
)
""")
result = run(testdir, file_format, variables=[{"foo": "bar"}, {"bar": "foo"}])
assert result.ret == 0


def test_multiple_variables_override(testdir, file_format):
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['foo'] == 'bar'
assert variables['bar'] == 'foo'
"""
)
""")
result = run(
testdir, file_format, variables=[{"foo": "foo", "bar": "foo"}, {"foo": "bar"}]
)
Expand All @@ -132,14 +118,12 @@ def test(variables):

def test_multiple_variables_merge_override(testdir, file_format):
"""Dictionaries merge when there are shared keys"""
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['capabilities']['browser'] == 'Firefox'
assert variables['capabilities']['browser_version'] == '53.0'
assert variables['capabilities']['debug'] == 'true'
"""
)
""")
result = run(
testdir,
file_format,
Expand All @@ -153,13 +137,11 @@ def test(variables):

def test_multiple_variables_merge_not_override_lists(testdir, file_format):
"""no lists extension, last wins"""
testdir.makepyfile(
"""
testdir.makepyfile("""
def test(variables):
assert variables['list'] == [4, 5]
assert variables['foo']['bar'] == 'true'
"""
)
""")
result = run(
testdir,
file_format,
Expand Down