From 8d1c521acaa8f8016ef21ed769c3b32f873fdf1f Mon Sep 17 00:00:00 2001 From: harupy Date: Tue, 15 Aug 2023 10:58:00 +0900 Subject: [PATCH] Import pytest Signed-off-by: harupy --- .../flake8_pytest_style/rules/assertion.rs | 12 ++++ .../flake8_pytest_style/rules/fixture.rs | 60 +++++++++++++++++++ .../rules/flake8_pytest_style/rules/marks.rs | 9 +++ .../flake8_pytest_style/rules/parametrize.rs | 12 ++++ .../rules/flake8_pytest_style/rules/raises.rs | 12 ++++ 5 files changed, 105 insertions(+) diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs index 5514cd8744a03..7b7407889ef97 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -92,6 +92,9 @@ impl Violation for PytestCompositeAssertion { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// def test_foo(): /// with pytest.raises(ZeroDivisionError) as exc_info: /// 1 / 0 @@ -130,6 +133,9 @@ impl Violation for PytestAssertInExcept { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// def test_foo(): /// if some_condition: /// pytest.fail("some_condition was True") @@ -157,6 +163,9 @@ impl Violation for PytestAssertAlwaysFalse { /// /// ## Example /// ```python +/// import unittest +/// +/// /// class TestFoo(unittest.TestCase): /// def test_foo(self): /// self.assertEqual(a, b) @@ -164,6 +173,9 @@ impl Violation for PytestAssertAlwaysFalse { /// /// Use instead: /// ```python +/// import unittest +/// +/// /// class TestFoo(unittest.TestCase): /// def test_foo(self): /// assert a == b diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs index 8651368dd2f85..771140db95db8 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs @@ -35,6 +35,9 @@ use super::helpers::{ /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture /// def my_fixture(): /// ... @@ -42,6 +45,9 @@ use super::helpers::{ /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture(): /// ... @@ -83,6 +89,9 @@ impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture("module") /// def my_fixture(): /// ... @@ -90,6 +99,9 @@ impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture(scope="module") /// def my_fixture(): /// ... @@ -118,6 +130,9 @@ impl Violation for PytestFixturePositionalArgs { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture(scope="function") /// def my_fixture(): /// ... @@ -125,6 +140,9 @@ impl Violation for PytestFixturePositionalArgs { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture(): /// ... @@ -158,6 +176,9 @@ impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def patch_something(mocker): /// mocker.patch("module.object") @@ -171,6 +192,9 @@ impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def _patch_something(mocker): /// mocker.patch("module.object") @@ -201,6 +225,9 @@ pub struct PytestMissingFixtureNameUnderscore { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def _some_object(): /// return SomeClass() @@ -215,6 +242,9 @@ pub struct PytestMissingFixtureNameUnderscore { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def some_object(): /// return SomeClass() @@ -268,6 +298,9 @@ impl Violation for PytestIncorrectFixtureNameUnderscore { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture /// def _patch_something(): /// ... @@ -279,6 +312,9 @@ impl Violation for PytestIncorrectFixtureNameUnderscore { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture /// def _patch_something(): /// ... @@ -362,6 +398,9 @@ impl Violation for PytestDeprecatedYieldFixture { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture(request): /// resource = acquire_resource() @@ -371,6 +410,9 @@ impl Violation for PytestDeprecatedYieldFixture { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture(): /// resource = acquire_resource() @@ -411,6 +453,9 @@ impl Violation for PytestFixtureFinalizerCallback { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture(): /// resource = acquire_resource() @@ -419,6 +464,9 @@ impl Violation for PytestFixtureFinalizerCallback { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def my_fixture_with_teardown(): /// resource = acquire_resource() @@ -460,6 +508,9 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def a(): /// pass @@ -473,6 +524,9 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// def a(): /// pass @@ -507,6 +561,9 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.mark.asyncio() /// @pytest.fixture() /// async def my_fixture(): @@ -515,6 +572,9 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.fixture() /// async def my_fixture(): /// return 0 diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs index 88f49d1702890..7a26b7ff2a1e7 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs @@ -23,6 +23,9 @@ use super::helpers::get_mark_decorators; /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.mark.foo /// def test_something(): /// ... @@ -30,6 +33,9 @@ use super::helpers::get_mark_decorators; /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.mark.foo() /// def test_something(): /// ... @@ -76,6 +82,9 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle { /// /// ## Example /// ```python +/// import pytest +/// +/// /// @pytest.mark.usefixtures() /// def test_something(): /// ... diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs index 383bd3840e9ad..931e8e6107833 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -26,6 +26,9 @@ use super::helpers::{is_pytest_parametrize, split_names}; /// /// ## Example /// ```python +/// import pytest +/// +/// /// # single parameter, always expecting string /// @pytest.mark.parametrize(("param",), [1, 2, 3]) /// def test_foo(param): @@ -46,6 +49,9 @@ use super::helpers::{is_pytest_parametrize, split_names}; /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.mark.parametrize("param", [1, 2, 3]) /// def test_foo(param): /// ... @@ -93,6 +99,9 @@ impl Violation for PytestParametrizeNamesWrongType { /// /// ## Example /// ```python +/// import pytest +/// +/// /// # expected list, got tuple /// @pytest.mark.parametrize("param", (1, 2)) /// def test_foo(param): @@ -125,6 +134,9 @@ impl Violation for PytestParametrizeNamesWrongType { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// @pytest.mark.parametrize("param", [1, 2, 3]) /// def test_foo(param): /// ... diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs index f44ad46824409..759cba2659f37 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs @@ -22,6 +22,9 @@ use super::helpers::is_empty_or_null_string; /// /// ## Example /// ```python +/// import pytest +/// +/// /// def test_foo(): /// with pytest.raises(MyError): /// setup() # may raise `MyError` @@ -31,6 +34,9 @@ use super::helpers::is_empty_or_null_string; /// /// Use instead: /// ```python +/// import pytest +/// +/// /// def test_foo(): /// setup() /// with pytest.raises(MyException): @@ -63,6 +69,9 @@ impl Violation for PytestRaisesWithMultipleStatements { /// /// ## Example /// ```python +/// import pytest +/// +/// /// def test_foo(): /// with pytest.raises(ValueError): /// ... @@ -74,6 +83,9 @@ impl Violation for PytestRaisesWithMultipleStatements { /// /// Use instead: /// ```python +/// import pytest +/// +/// /// def test_foo(): /// with pytest.raises(ValueError, match="expected message"): /// ...