Skip to content

Commit

Permalink
update ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Dec 3, 2024
1 parent eaedfec commit ebd6855
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 53 deletions.
21 changes: 11 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ source = "file"
path = "pytest_robotframework/_internal/__init__.py"


[tool.ruff.format]
skip-magic-trailing-comma = true
docstring-code-format = true

[tool.pylint.MASTER]
fail-on = "I"
bad-names = ["foo", "bar", "baz", "retval"]
Expand Down Expand Up @@ -187,10 +183,10 @@ enable_assertion_pass_hook = true
[tool.basedpyright]
ignore = ["pw"]
pythonVersion = "3.9"
reportMissingTypeStubs = false # https://github.com/robotframework/robotframework/issues/4822
reportImplicitStringConcatenation = true # ideally this should be off and handled by the ruff formatter https://github.com/astral-sh/ruff/issues/9965
reportUnusedImport = false # covered by ruff (has quickfix)
reportUnusedVariable = false # covered by ruff (has quickfix)
reportMissingTypeStubs = false # https://github.com/robotframework/robotframework/issues/4822
reportImplicitStringConcatenation = false # handled by ruff
reportUnusedImport = false # covered by ruff (has quickfix)
reportUnusedVariable = false # covered by ruff (has quickfix)

[tool.ruff]
unsafe-fixes = true
Expand Down Expand Up @@ -248,13 +244,14 @@ ignore = [
"UP035", # deprecated-import (covered by pyright)
"ISC001", # single-line-implicit-string-concatenation (conflicts with formatter)
"COM812", # missing-trailing-comma (conflicts with formatter)
"ISC003", # explicit-string-concatenation (https://github.com/astral-sh/ruff/issues/9965)
"W293", # modifies strings (https://github.com/astral-sh/ruff/issues/10038)
"PLE1507", # invalid-envvar-value (covered by pyright)
"D200", # fits-on-one-line (https://github.com/astral-sh/ruff/issues/6269)
"DOC201", # docstring-missing-returns
"DOC501", # docstring-missing-exception (https://github.com/astral-sh/ruff/issues/12520)
"ARG001", # unused-function-argument (covered by basedpyright)
"TC006", # runtime-cast-value (quoted types look disgusting)
"W291", # trailing-whitespace (covered by formatter + false positives inside multiline strings)
"W293", # blank-line-with-whitespace (covered by formatter + false positives inside multiline strings)
]

[tool.ruff.lint.flake8-pytest-style]
Expand All @@ -270,6 +267,10 @@ combine-as-imports = true
required-imports = ["from __future__ import annotations"]
split-on-trailing-comma = false

[tool.ruff.format]
skip-magic-trailing-comma = true
docstring-code-format = true

[tool.robotidy]
configure = [
"AlignTemplatedTestCases:enabled=True",
Expand Down
8 changes: 4 additions & 4 deletions pytest_robotframework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def _get_failure(self, *args: Never, **kwargs: Never):
str(
InternalError(
"failed to filter out pytest-robotframework machinery for exception: "
+ f"{exc_value!r}\n\nfull traceback:\n\n"
+ "".join(format_stack())
f"{exc_value!r}\n\nfull traceback:\n\n"
"".join(format_stack())
)
)
)
Expand Down Expand Up @@ -316,7 +316,7 @@ class _FunctionKeywordDecorator(_KeywordDecorator):

@deprecated(
"you must explicitly pass `wrap_context_manager` when using `keyword` with a"
+ " context manager"
" context manager"
)
@overload
def __call__(self, fn: Callable[P, AbstractContextManager[T]]) -> Never: ...
Expand Down Expand Up @@ -602,7 +602,7 @@ def inner(*args: P.args, **kwargs: P.kwargs) -> T:
# stack trace isn't showsn so we neewd to include the original error in the
# message as well
f"an error occurred inside {cls.__name__} and failed to get the"
+ f" current pytest item/session: {e}"
f" current pytest item/session: {e}"
) from e
add_robot_error(item_or_session, str(e))
raise
Expand Down
6 changes: 3 additions & 3 deletions pytest_robotframework/_internal/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NotSupportedError(PytestRobotError):
def __init__(self, message: str, issue_number: int) -> None:
super().__init__(
f"the pytest-robotframework plugindoes not yet support {message}. see"
+ f" https://github.com/detachhead/pytest-robotframework/issues/{issue_number}"
f" https://github.com/detachhead/pytest-robotframework/issues/{issue_number}"
)


Expand All @@ -25,6 +25,6 @@ class InternalError(PytestRobotError):
def __init__(self, message: str) -> None:
super().__init__(
"something went wrong with the pytest-robotframework plugin. please raise"
+ " an issue at https://github.com/detachhead/pytest-robotframework with the"
+ f" following information:\n\n{message}"
" an issue at https://github.com/detachhead/pytest-robotframework with the"
f" following information:\n\n{message}"
)
12 changes: 6 additions & 6 deletions pytest_robotframework/_internal/pytest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def _run_robot(session: Session, robot_options: InternalRobotOptions):
if exit_code and not session.testsfailed:
raise Exception(
f"pytest-robotframework detected that robot failed with exit code {exit_code} despite"
+ " no tests failing. this may have been caused by a robot error that occurred"
+ " before any tests started."
" no tests failing. this may have been caused by a robot error that occurred"
" before any tests started."
)


Expand Down Expand Up @@ -382,17 +382,17 @@ def pytest_addoption(parser: Parser):
group = parser.getgroup(
"robot",
"robotframework (if an option is missing, it means there's a pytest equivalent you should"
+ "use instead. see https://github.com/DetachHead/pytest-robotframework#config)",
"use instead. see https://github.com/DetachHead/pytest-robotframework#config)",
)
group.addoption(
"--no-assertions-in-robot-log",
dest="assertions_in_robot_log",
default=True,
action="store_false",
help="whether to hide passing `assert` statements in the robot log by default. when this is"
+ " disabled, you can make individual `assert` statements show in the log using the"
+ " `pytest_robotframework.AssertionOptions` class with `log_pass=True`. see the docs for"
+ " more information: https://github.com/DetachHead/pytest-robotframework/tree/assertion-ricing#hiding-non-user-facing-assertions",
" disabled, you can make individual `assert` statements show in the log using the"
" `pytest_robotframework.AssertionOptions` class with `log_pass=True`. see the docs for"
" more information: https://github.com/DetachHead/pytest-robotframework/tree/assertion-ricing#hiding-non-user-facing-assertions",
)
for arg_name, default_value in cli_defaults(RobotSettings).items():
if arg_name in banned_options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def log_message(self, message: model.Message):
elif not self.current_test:
raise InternalError(
"a robot error occurred and ErrorDetector failed to figure out what test it came"
+ f"from: {message.message}"
f"from: {message.message}"
)
else:
item_or_session = (
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __bool__(self) -> Literal[True]:
def __len__(self) -> Never:
raise Exception(
"cannot call `len()` on `XmlElement` to count its children, use `count_children` "
+ "instead"
"instead"
)

@override
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
46 changes: 25 additions & 21 deletions tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_one_test_skipped(pr: PytestRobotTester):
pr.assert_log_file_exists()
assert output_xml().xpath(
"./suite//test[@name='test_one_test_skipped']/kw[@type='SETUP']/msg[@level='SKIP' and "
+ ".='Skipped: foo']"
".='Skipped: foo']"
)


Expand Down Expand Up @@ -75,11 +75,11 @@ def test_nested_suites(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"./suite/suite[@name='Suite1']/suite[@name='Suite2']/suite[@name='Test"
+ " Asdf']/test[@name='test_func1']"
" Asdf']/test[@name='test_func1']"
)
assert xml.xpath(
"./suite/suite[@name='Suite1']/suite[@name='Suite3']/suite[@name='Test"
+ " Asdf2']/test[@name='test_func2']"
" Asdf2']/test[@name='test_func2']"
)
assert xml.xpath("./suite/suite[@name='Test Top Level']/test[@name='test_func1']")

Expand Down Expand Up @@ -233,11 +233,11 @@ def test_error_moment_and_second_test(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
".//test[@name='test_foo' and ./status[@status='FAIL']]/kw[@name='Run"
+ " Test']/msg[@level='ERROR' and .='foo']"
" Test']/msg[@level='ERROR' and .='foo']"
)
assert xml.xpath(
".//test[@name='test_bar' and ./status[@status='PASS']]/kw[@name='Run"
+ " Test']/msg[@level='INFO' and .='bar']"
" Test']/msg[@level='INFO' and .='bar']"
)


Expand All @@ -262,13 +262,13 @@ def test_error_moment_exitonerror_multiple_tests(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
".//test[@name='test_foo' and ./status[@status='FAIL']]/kw[@name='Run"
+ " Test']/msg[@level='ERROR' and .='foo']"
" Test']/msg[@level='ERROR' and .='foo']"
)
assert (
bool(
xml.xpath(
".//test[@name='test_bar']/status[@status='FAIL' and .='Error occurred"
+ " and exit-on-error mode is in use.']"
" and exit-on-error mode is in use.']"
)
)
!= pr.xdist
Expand Down Expand Up @@ -322,11 +322,11 @@ def test_keyword_decorator_args(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
".//test[@name='test_no_truncation']//kw[@name='Run Test']/kw[@name='Foo' and ./arg[.='1']"
+ " and ./arg[.='bar=True']]"
" and ./arg[.='bar=True']]"
)
assert xml.xpath(
".//test[@name='test_truncation']//kw[@name='Run Test']/kw[@name='Foo' and"
+ f" ./arg[.='{'a' * 50}...'] and ./arg[.='bar={'b' * 50}...']]"
f" ./arg[.='{'a' * 50}...'] and ./arg[.='bar={'b' * 50}...']]"
)


Expand Down Expand Up @@ -367,8 +367,8 @@ def test_keyword_decorator_context_manager_that_raises_in_body_and_exit(pr: Pyte
assert xml.xpath("//kw[@name='Asdf']/msg[@level='FAIL' and .='asdf']")
assert xml.xpath(
"//kw[@name='Asdf']/msg[@level='DEBUG' and contains(.,'Exception:"
+ " fdsa\n\nDuring handling of the above exception, another exception"
+ " occurred:') and contains(., 'Exception: asdf')]"
" fdsa\n\nDuring handling of the above exception, another exception"
" occurred:') and contains(., 'Exception: asdf')]"
)
assert not xml.xpath("//msg[.='1']")

Expand All @@ -384,7 +384,7 @@ def test_keyword_decorator_try_except(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//kw[@name='Run Test' and ./status[@status='PASS']]/kw[@name='Bar' and"
+ " ./status[@status='FAIL']]/msg[.='FooError']"
" ./status[@status='FAIL']]/msg[.='FooError']"
)
assert xml.xpath("//kw[@name='Run Test']/msg[.='hi']")

Expand All @@ -409,7 +409,7 @@ def test_keywordify_context_manager(pr: PytestRobotTester):
pr.assert_log_file_exists()
assert output_xml().xpath(
"//kw[@name='Raises' and ./arg[.=\"<class 'ZeroDivisionError'>\"] and"
+ " ./status[@status='PASS']]"
" ./status[@status='PASS']]"
)


Expand Down Expand Up @@ -528,7 +528,7 @@ def test_assertion_passes(pr: PytestRobotTester):
pr.assert_log_file_exists()
assert output_xml().xpath(
"//kw[@name='assert' and ./arg[.='left == right'] and ./status[@status='PASS']]"
+ "/msg[@level='INFO' and .='1 == 1']"
"/msg[@level='INFO' and .='1 == 1']"
)


Expand All @@ -538,7 +538,7 @@ def test_assertion_fails_with_assertion_hook(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='left == right'] and ./status[@status='FAIL']]"
+ "/msg[@level='FAIL' and .='assert 1 == 2']"
"/msg[@level='FAIL' and .='assert 1 == 2']"
)
# make sure the error was only logged once , since the exception gets re-raised after the
# keyword is over we want to make sure it's not printed multiple times
Expand All @@ -565,7 +565,7 @@ def test_assertion_passes_hide_assert(pr: PytestRobotTester):
assert not xml.xpath("//kw[@name='assert']/arg[.='right == left']")
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='right == right # noqa: PLR0124']]/msg[@level='INFO' and "
+ ".='1 == 1']"
".='1 == 1']"
)


Expand All @@ -578,11 +578,11 @@ def test_assertion_passes_custom_messages(pr: PytestRobotTester):
)
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='does appear1'] and ./msg[@level='INFO' and .='assert "
+ "right == left'] and ./msg[@level='INFO' and .='1 == 1']]"
"right == left'] and ./msg[@level='INFO' and .='1 == 1']]"
)
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='right == \"wrong\"'] and ./msg[@level='FAIL' and .=\"does"
+ " appear2\nassert 1 == 'wrong'\"]]"
" appear2\nassert 1 == 'wrong'\"]]"
)


Expand Down Expand Up @@ -611,7 +611,7 @@ def test_assertion_fails_with_fail_message_hide_assert(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='right == \"wrong\"']]/msg[@level='FAIL' and "
+ ".=\"asdf\nassert 1 == 'wrong'\"]"
".=\"asdf\nassert 1 == 'wrong'\"]"
)


Expand All @@ -620,8 +620,7 @@ def test_assertion_fails_with_description(pr: PytestRobotTester):
pr.assert_log_file_exists()
xml = output_xml()
assert xml.xpath(
"//kw[@name='assert' and ./arg[.='asdf']]/msg[@level='FAIL' and "
+ ".=\"assert 1 == 'wrong'\"]"
"//kw[@name='assert' and ./arg[.='asdf']]/msg[@level='FAIL' and .=\"assert 1 == 'wrong'\"]"
)


Expand Down Expand Up @@ -812,6 +811,11 @@ def test_full_stack_keyword_context_manager(cls, pr: PytestRobotTester):
assert cls.parse_stack_trace(result) == {17: "test_as_keyword", 8: "foo", 13: "bar"}


foo = """
foo
"""


def test_ansi(pr: PytestRobotTester):
pr.run_and_assert_result("-vv", "--color=yes", failed=1)
pr.assert_log_file_exists()
Expand Down
13 changes: 6 additions & 7 deletions tests/test_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_setup_fails(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//suite//test[@name='Foo']/kw[@type='SETUP']/kw[@name='Bar' and"
+ " .//msg[@level='FAIL' and .='asdf'] and .//status[@status='FAIL']]"
" .//msg[@level='FAIL' and .='asdf'] and .//status[@status='FAIL']]"
)
# make sure the test didnt run when setup failed
assert not xml.xpath("//kw[contains(@name, 'Run Test')]")
Expand Down Expand Up @@ -93,7 +93,7 @@ def test_teardown_fails(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//suite//test[@name='Foo']/kw[@type='TEARDOWN']/kw[@name='Bar' and"
+ " .//msg[@level='FAIL' and .='asdf'] and .//status[@status='FAIL']]"
" .//msg[@level='FAIL' and .='asdf'] and .//status[@status='FAIL']]"
)
assert xml.xpath("//kw[contains(@name, 'Run Test')]")

Expand All @@ -105,8 +105,7 @@ def test_teardown_skipped(pr: PytestRobotTester):
pr.assert_log_file_exists()
xml = output_xml()
assert xml.xpath(
"//suite//test[@name='Foo']/kw[@type='TEARDOWN']/kw[@name='Bar' and"
+ " .//msg[@level='SKIP']]"
"//suite//test[@name='Foo']/kw[@type='TEARDOWN']/kw[@name='Bar' and .//msg[@level='SKIP']]"
)
assert xml.xpath("//kw[contains(@name, 'Run Test')]")

Expand Down Expand Up @@ -233,7 +232,7 @@ def test_setup_with_args(pr: PytestRobotTester):
xml = output_xml()
assert xml.xpath(
"//kw[@type='SETUP']/kw[@name='Run Keywords' and ./arg[.='Bar'] and"
+ " ./arg[.='AND'] and ./arg[.='Baz']]"
" ./arg[.='AND'] and ./arg[.='Baz']]"
)


Expand Down Expand Up @@ -318,12 +317,12 @@ def test_empty_setup_or_teardown(pr: PytestRobotTester):
assert xpath(
xml,
"//test[@name='Runs globally defined setup and teardown']/kw[@name='Setup']/kw[@name='Log']"
+ "/msg[.='setup ran']",
"/msg[.='setup ran']",
)
assert xpath(
xml,
"//test[@name='Runs globally defined setup and teardown']/kw[@name='Teardown']"
+ "/kw[@name='Log']/msg[.='teardown ran']",
"/kw[@name='Log']/msg[.='teardown ran']",
)
assert not xml.xpath("//test[@name='Disable setup']/kw[@name='Setup']/kw[@name='Log']")
assert not xml.xpath("//test[@name='Disable teardown']/kw[@name='Teardown']/kw[@name='Log']")
Expand Down

0 comments on commit ebd6855

Please sign in to comment.