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
Expand Up @@ -8,7 +8,7 @@ repos:
language: python
additional_dependencies: [pygments, restructuredtext_lint]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.16
rev: v0.16.0
hooks:
- id: ruff
args: ["--fix"]
Expand Down
4 changes: 1 addition & 3 deletions random_order/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def pytest_report_header(config):
plugin = Config(config)
if not plugin.is_enabled:
return "Test order randomisation NOT enabled. Enable with --random-order or --random-order-bucket=<bucket_type>"
return ("Using --random-order-bucket={plugin.bucket_type}\nUsing --random-order-seed={plugin.seed}\n").format(
plugin=plugin
)
return f"Using --random-order-bucket={plugin.bucket_type}\nUsing --random-order-seed={plugin.seed}\n"


def pytest_collection_modifyitems(session, config, items):
Expand Down
2 changes: 0 additions & 2 deletions random_order/shuffler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

import random
from collections import OrderedDict, namedtuple

Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs
import os
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def get_test_calls():
def twenty_tests():
code = []
for i in range(20):
code.append("def test_a{0}(): assert True\n".format(str(i).zfill(2)))
code.append(f"def test_a{str(i).zfill(2)}(): assert True\n")
return "".join(code)


@pytest.fixture
def twenty_cls_tests():
code = []
for i in range(20):
code.append("\tdef test_b{0}(self): self.assertTrue\n".format(str(i).zfill(2)))
code.append(f"\tdef test_b{str(i).zfill(2)}(self): self.assertTrue\n")
return "".join(code)
19 changes: 9 additions & 10 deletions tests/test_actual_test_runs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import collections
import re
import textwrap
Expand Down Expand Up @@ -164,7 +163,7 @@ def test_it_works_with_actual_tests(tmp_tree_of_tests, get_test_calls, bucket, m
sequences = set()

for x in range(5):
result = tmp_tree_of_tests.runpytest("--random-order-bucket={0}".format(bucket), "--verbose")
result = tmp_tree_of_tests.runpytest(f"--random-order-bucket={bucket}", "--verbose")
result.assert_outcomes(passed=14, failed=3)
seq = get_test_calls(result)
check_call_sequence(seq, bucket=bucket)
Expand All @@ -181,20 +180,20 @@ def test_random_order_seed_is_respected(testdir, twenty_tests, get_test_calls):
"2": None,
"3": None,
}
for seed in call_sequences.keys():
result = testdir.runpytest("--random-order-seed={0}".format(seed))
for seed in call_sequences:
result = testdir.runpytest(f"--random-order-seed={seed}")

result.stdout.fnmatch_lines(
[
"*Using --random-order-seed={0}*".format(seed),
f"*Using --random-order-seed={seed}*",
]
)

result.assert_outcomes(passed=20)
call_sequences[seed] = get_test_calls(result)

for seed in call_sequences.keys():
result = testdir.runpytest("--random-order-seed={0}".format(seed))
for seed in call_sequences:
result = testdir.runpytest(f"--random-order-seed={seed}")
result.assert_outcomes(passed=20)
assert call_sequences[seed] == get_test_calls(result)

Expand All @@ -217,7 +216,7 @@ def test_generated_seed_is_reported_and_run_can_be_reproduced(testdir, twenty_te
break
assert seed

result2 = testdir.runpytest("-v", "--random-order-seed={0}".format(seed))
result2 = testdir.runpytest("-v", f"--random-order-seed={seed}")
result2.assert_outcomes(passed=20)
calls2 = get_test_calls(result2)
assert calls == calls2
Expand All @@ -236,10 +235,10 @@ def test_generated_seed_is_reported_and_run_can_be_reproduced(testdir, twenty_te
],
)
def test_failed_first(tmp_tree_of_tests, get_test_calls, bucket):
result1 = tmp_tree_of_tests.runpytest("--random-order-bucket={0}".format(bucket), "--verbose")
result1 = tmp_tree_of_tests.runpytest(f"--random-order-bucket={bucket}", "--verbose")
result1.assert_outcomes(passed=14, failed=3)

result2 = tmp_tree_of_tests.runpytest("--random-order-bucket={0}".format(bucket), "--failed-first", "--verbose")
result2 = tmp_tree_of_tests.runpytest(f"--random-order-bucket={bucket}", "--failed-first", "--verbose")
result2.assert_outcomes(passed=14, failed=3)

calls2 = get_test_calls(result2)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import textwrap

import pytest
Expand Down Expand Up @@ -56,7 +55,7 @@ def subtract(a, b):
def test_doctests(tmp_tree_of_tests, get_test_calls, bucket):
result1 = tmp_tree_of_tests.runpytest(
"--doctest-modules",
"--random-order-bucket={0}".format(bucket),
f"--random-order-bucket={bucket}",
"--verbose",
"-s",
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@pytest.mark.parametrize("disabled", [True, False])
def test_marker_disables_random_order_in_module(testdir, twenty_tests, get_test_calls, disabled):
testdir.makepyfile(
"import pytest\n" + ("pytestmark = pytest.mark.random_order(disabled={0})\n".format(disabled)) + twenty_tests
"import pytest\n" + (f"pytestmark = pytest.mark.random_order(disabled={disabled})\n") + twenty_tests
)

result = testdir.runpytest("--random-order", "-v")
Expand All @@ -24,7 +24,7 @@ def test_marker_disables_random_order_in_class(testdir, twenty_cls_tests, get_te
"import pytest\n\n"
+ "from unittest import TestCase\n\n"
+ "class MyTest(TestCase):\n"
+ "\tpytestmark = pytest.mark.random_order(disabled={0})\n".format(disabled)
+ f"\tpytestmark = pytest.mark.random_order(disabled={disabled})\n"
+ twenty_cls_tests
+ "\n"
)
Expand Down