Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import pytest in flake8-pytest-style docs #6580

Merged
merged 1 commit into from
Aug 15, 2023
Merged
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
12 changes: 12 additions & 0 deletions crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -157,13 +163,19 @@ impl Violation for PytestAssertAlwaysFalse {
///
/// ## Example
/// ```python
/// import unittest
///
///
/// class TestFoo(unittest.TestCase):
/// def test_foo(self):
/// self.assertEqual(a, b)
/// ```
///
/// Use instead:
/// ```python
/// import unittest
///
///
/// class TestFoo(unittest.TestCase):
/// def test_foo(self):
/// assert a == b
Expand Down
60 changes: 60 additions & 0 deletions crates/ruff/src/rules/flake8_pytest_style/rules/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ use super::helpers::{
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def my_fixture():
/// ...
/// ```
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// ...
Expand Down Expand Up @@ -83,13 +89,19 @@ impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture("module")
/// def my_fixture():
/// ...
/// ```
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture(scope="module")
/// def my_fixture():
/// ...
Expand Down Expand Up @@ -118,13 +130,19 @@ impl Violation for PytestFixturePositionalArgs {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture(scope="function")
/// def my_fixture():
/// ...
/// ```
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// ...
Expand Down Expand Up @@ -158,6 +176,9 @@ impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def patch_something(mocker):
/// mocker.patch("module.object")
Expand All @@ -171,6 +192,9 @@ impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def _patch_something(mocker):
/// mocker.patch("module.object")
Expand Down Expand Up @@ -201,6 +225,9 @@ pub struct PytestMissingFixtureNameUnderscore {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def _some_object():
/// return SomeClass()
Expand All @@ -215,6 +242,9 @@ pub struct PytestMissingFixtureNameUnderscore {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def some_object():
/// return SomeClass()
Expand Down Expand Up @@ -268,6 +298,9 @@ impl Violation for PytestIncorrectFixtureNameUnderscore {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def _patch_something():
/// ...
Expand All @@ -279,6 +312,9 @@ impl Violation for PytestIncorrectFixtureNameUnderscore {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture
/// def _patch_something():
/// ...
Expand Down Expand Up @@ -362,6 +398,9 @@ impl Violation for PytestDeprecatedYieldFixture {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture(request):
/// resource = acquire_resource()
Expand All @@ -371,6 +410,9 @@ impl Violation for PytestDeprecatedYieldFixture {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// resource = acquire_resource()
Expand Down Expand Up @@ -411,6 +453,9 @@ impl Violation for PytestFixtureFinalizerCallback {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture():
/// resource = acquire_resource()
Expand All @@ -419,6 +464,9 @@ impl Violation for PytestFixtureFinalizerCallback {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def my_fixture_with_teardown():
/// resource = acquire_resource()
Expand Down Expand Up @@ -460,6 +508,9 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def a():
/// pass
Expand All @@ -473,6 +524,9 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// def a():
/// pass
Expand Down Expand Up @@ -507,6 +561,9 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.mark.asyncio()
/// @pytest.fixture()
/// async def my_fixture():
Expand All @@ -515,6 +572,9 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.fixture()
/// async def my_fixture():
/// return 0
Expand Down
9 changes: 9 additions & 0 deletions crates/ruff/src/rules/flake8_pytest_style/rules/marks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ use super::helpers::get_mark_decorators;
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.mark.foo
/// def test_something():
/// ...
/// ```
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.mark.foo()
/// def test_something():
/// ...
Expand Down Expand Up @@ -76,6 +82,9 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// @pytest.mark.usefixtures()
/// def test_something():
/// ...
Expand Down
12 changes: 12 additions & 0 deletions crates/ruff/src/rules/flake8_pytest_style/rules/parametrize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
/// ...
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -125,6 +134,9 @@ impl Violation for PytestParametrizeNamesWrongType {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// @pytest.mark.parametrize("param", [1, 2, 3])
/// def test_foo(param):
/// ...
Expand Down
12 changes: 12 additions & 0 deletions crates/ruff/src/rules/flake8_pytest_style/rules/raises.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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):
Expand Down Expand Up @@ -63,6 +69,9 @@ impl Violation for PytestRaisesWithMultipleStatements {
///
/// ## Example
/// ```python
/// import pytest
///
///
/// def test_foo():
/// with pytest.raises(ValueError):
/// ...
Expand All @@ -74,6 +83,9 @@ impl Violation for PytestRaisesWithMultipleStatements {
///
/// Use instead:
/// ```python
/// import pytest
///
///
/// def test_foo():
/// with pytest.raises(ValueError, match="expected message"):
/// ...
Expand Down
Loading