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
10 changes: 7 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ repos:
hooks:
- id: ruff-format
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.0
- repo: local
hooks:
- id: mypy
- id: ty
name: ty
entry: ty check
language: system
types: [python]
pass_filenames: false
- repo: https://github.com/keewis/blackdoc
rev: v0.4.6
hooks:
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "pytest-accept"
urls = { homepage = "https://github.com/max-sixty/pytest-accept", repository = "https://github.com/max-sixty/pytest-accept" }

[dependency-groups]
dev = ["blackdoc", "mypy", "pre-commit", "pytest-xdist>=3.8.0", "ruff"]
dev = ["blackdoc", "pre-commit", "pytest-xdist>=3.8.0", "ruff"]

[project.entry-points.pytest11]
accept = "pytest_accept"
Expand Down Expand Up @@ -47,8 +47,3 @@ select = [
"I", # isort
"UP", # Pyupgrade
]

[tool.mypy]
files = "."
# TODO: ideally we would list the modules that aren't yet typed
ignore_missing_imports = true
19 changes: 11 additions & 8 deletions pytest_accept/assert_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def new_visit_assert(self, assert_):

# Add simple safety check - if there are too many AST nodes, skip wrapping
# This prevents "too many statically nested blocks" errors in edge cases
total_nodes = sum(1 for _ in ast.walk(ast.Module(body=rv)))
total_nodes = sum(1 for _ in ast.walk(ast.Module(body=rv, type_ignores=[])))
if total_nodes > 200: # Higher threshold - only skip for very complex cases
# module_path is an internal pytest attribute that may not exist in all versions
if hasattr(self, "module_path"):
Expand Down Expand Up @@ -145,7 +145,7 @@ def new_visit_assert(self, assert_):

return [try_except]

AssertionRewriter.visit_Assert = new_visit_assert
AssertionRewriter.visit_Assert = new_visit_assert # type: ignore[method-assign]


def __handle_failed_assertion():
Expand Down Expand Up @@ -184,26 +184,29 @@ def __handle_failed_assertion_impl(raw_excinfo, session, left):
line_number_end = line_number_start + len(tb_entry.statement.lines) - 1
original_location = slice(line_number_start, line_number_end)

path = tb_entry.path
path = Path(tb_entry.path)
with path.open() as f:
tree = ast.parse(f.read())

for item in ast.walk(tree):
if isinstance(item, ast.Assert) and original_location.start == item.lineno:
# we need to _then_ check that the next compare item's
# ops[0] is Eq and then replace the comparator[0]
test = item.test
if not isinstance(test, ast.Compare):
continue
try:
assert item.msg is None
assert len(item.test.comparators) == 1
assert len(item.test.ops) == 1
assert isinstance(item.test.ops[0], ast.Eq)
assert len(test.comparators) == 1
assert len(test.ops) == 1
assert isinstance(test.ops[0], ast.Eq)

ast.literal_eval(item.test.comparators[0])
ast.literal_eval(test.comparators[0])
except Exception:
continue

new_assert = copy.copy(item)
new_assert.test.comparators[0] = ast.Constant(value=left)
test.comparators[0] = ast.Constant(value=left)

# Submit change to unified change collection
file_changes = session.stash.setdefault(file_changes_key, {})
Expand Down
48 changes: 1 addition & 47 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading