Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
pre-commit fixes
  • Loading branch information
zmievsa committed Aug 17, 2023
commit 29f415e4f54b3bbc3f5ba2ac951bdf873ca9e82f
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ old-version/
/site/
/site.zip
/build/
.venv
.venv
13 changes: 8 additions & 5 deletions devtools/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def insert_pytest_raises() -> Generator[None, Any, int]:
yield
except Exception as e:
python_code = format_code(
f'# with insert_pytest_raises():\nwith pytest.raises({type(e).__name__}, match=re.escape({repr(str(e))})):\n'
f'# with insert_pytest_raises():\n'
f'with pytest.raises({type(e).__name__}, match=re.escape({repr(str(e))})):\n'
)
python_code = textwrap.indent(python_code, statement.col_offset * ' ')
to_replace.append(
Expand Down Expand Up @@ -215,19 +216,21 @@ def insert_assert_session(pytestconfig: pytest.Config) -> Generator[None, None,
files += 1
prefix = 'Printed' if print_instead else 'Replaced'

insert_assert_count = len([item for item in to_replace if item.instruction_type == "insert_assert"])
insert_pytest_raises_count = len([item for item in to_replace if item.instruction_type == "insert_pytest_raises"])
insert_assert_count = len([item for item in to_replace if item.instruction_type == 'insert_assert'])
insert_pytest_raises_count = len([item for item in to_replace if item.instruction_type == 'insert_pytest_raises'])
if insert_assert_count:
summary.append(
f'{prefix} {insert_assert_count} insert_assert() call{plural(to_replace)} in {files} file{plural(files)}'
)
if insert_pytest_raises_count:
summary.append(
f'{prefix} {insert_pytest_raises_count} insert_pytest_raises() call{plural(to_replace)} in {files} file{plural(files)}'
f'{prefix} {insert_pytest_raises_count} insert_pytest_raises()'
f' call{plural(to_replace)} in {files} file{plural(files)}'
)
if dup_count:
summary.append(
f'\n{dup_count} insert{plural(dup_count)} skipped because an assert statement on that line had already be inserted!'
f'\n{dup_count} insert{plural(dup_count)}'
' skipped because an assert statement on that line had already be inserted!'
)

test_replacement_summary.set(summary)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_insert_pytest_raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import pytest

from devtools.pytest_plugin import load_black

pytestmark = pytest.mark.skipif(sys.version_info < (3, 8), reason='requires Python 3.8+')


Expand Down Expand Up @@ -160,6 +158,6 @@ def test_raise_keyerror(insert_pytest_raises):
result.assert_outcomes(failed=1)
captured = capsys.readouterr()
assert (
"RuntimeError: insert_pytest_raises() was called alongside other statements, this is not supported\n"
'RuntimeError: insert_pytest_raises() was called alongside other statements, this is not supported\n'
in captured.out
)