Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
tmp.py
log.txt
stdout.txt
out.txt
stderr.txt
err.txt
notes.txt
TODO
*.pseudo
*.patch
nohup*

### Python ###
# Byte-compiled / optimized / DLL files
Expand Down
2 changes: 1 addition & 1 deletion .mirror.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# DANGER: EDIT AT YOUR OWN RISK. Track this file in version control so that others can sync files correctly.
- commit: 4bf378ac9f437becb4c869e3b2b09c8f3adbc074
- commit: 4519f0a82ab20cd50ec11c717ac75abcff7ea16c
files:
- .github/python-release.yaml
- .github/python-test.yaml
Expand Down
12 changes: 8 additions & 4 deletions mypy_pytest_plugin/fixture_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ def resolution_sequence(cls, name: Fullname) -> Iterable[Fullname]:
@functools.lru_cache
def default_fixture_module_names(cls) -> Sequence[Fullname]:
config = _pytest.config.get_config()
config.parse(["-s", "--fixtures", "--noconftest"])
config.parse(["-s", "--fixtures"])

session = Session.from_config(config)
fixture_manager = PytestFixtureManager(session)
return tuple(
{
cls._fixture_module(fixture_defs[-1])
module
for fixture_defs in fixture_manager._arg2fixturedefs.values()
if (module := cls._fixture_module(fixture_defs[-1])) is not None
}
)

@classmethod
def _fixture_module(cls, fixture: FixtureDef) -> Fullname:
return Fullname.from_string(fixture.func.__module__)
def _fixture_module(cls, fixture: FixtureDef) -> Fullname | None:
module = Fullname.from_string(fixture.func.__module__)
if module == Fullname.from_string("conftest"):
return None
return module

@filter_unique
def autouse_fixture_names(self, test_module: Fullname) -> Iterable[str]:
Expand Down
2 changes: 2 additions & 0 deletions mypy_pytest_plugin/fixture_manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ def test_fixture_manager_default_fixture_module_names() -> None:
"_pytest.doctest",
"_pytest.fixtures",
"_pytest.junitxml",
"_pytest.legacypath",
"_pytest.logging",
"_pytest.monkeypatch",
"_pytest.pytester",
"_pytest.recwarn",
"_pytest.subtests",
"_pytest.tmpdir",
Expand Down
2 changes: 1 addition & 1 deletion mypy_pytest_plugin/pytest_config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PytestConfigManager:
@functools.cache
def session(cls) -> Session:
config = _pytest.config.get_config()
config.parse(["-s", "--noconftest"])
config.parse(["-s"])
return Session.from_config(config)

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-r requirements.txt
git+https://github.com/George-Ogden/mirror-rorrim
git+https://github.com/George-Ogden/mirror-rorrim; python_version >= "3.12"
git+https://github.com/George-Ogden/mypy-pytest; python_version >= "3.12"
git+https://github.com/George-Ogden/pytest-dbg
inline-snapshot
pip
Expand Down
6 changes: 6 additions & 0 deletions test_samples/broken_conftest/broken_conftest_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.mark.skip
def test_case() -> int:
return 0
6 changes: 6 additions & 0 deletions test_samples/broken_conftest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
@pytest.mark.skip
def fixture_and_mark() -> None: ...
8 changes: 3 additions & 5 deletions test_samples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ def indirect_int_fixture(base_int_fixture: int) -> int:
return base_int_fixture + 1


@pytest.fixture
@pytest.mark.skip
def fixture_and_mark() -> None: ...


def missed_fixture_decorator_in_another_file() -> int:
return 0

Expand All @@ -41,3 +36,6 @@ def ordered_fixture1() -> Literal[0]:
@pytest.fixture
def ordered_fixture2() -> Literal[1]:
return 1


pytest_plugins = "pytester"
6 changes: 5 additions & 1 deletion test_samples/valid_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Literal
from pytest import CaptureFixture
from pytest import CaptureFixture, Pytester

import pytest

Expand Down Expand Up @@ -38,3 +38,7 @@ def test_iterable_sequence_builtin() -> None:


def test_use_builtin_fixture(capsys: CaptureFixture[str]) -> None: ...


@pytest.mark.skip
def test_pytester_fixture(pytester: Pytester) -> None: ...
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
test_samples/conftest.py:33: error: 'autouse_fixture' (scope='module') requests 'autouse_request' (scope='function'). [inverted-fixture-scope]
test_samples/conftest.py:28: error: 'autouse_fixture' (scope='module') requests 'autouse_request' (scope='function'). [inverted-fixture-scope]
test_samples/autouse_test.py:10: error: 'request_autouse_fixture' (scope='package') requests 'autouse_request' (scope='function'). [inverted-fixture-scope]
test_samples/conftest.py:33: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/conftest.py:28: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/autouse_test.py:10: error: 'request_autouse_fixture' requests 'autouse_request' with type "str", but expects type "int". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/autouse_test.py:31: error: 'late_autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/conftest.py:29: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/conftest.py:24: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_direct_request_autouse_fixture'. [fixture-arg-type]
test_samples/autouse_test.py:22: error: Argument 1 has incompatible type "tuple[()]"; expected "ParameterSet[None] | None" [arg-type]
test_samples/autouse_test.py:35: error: Argname 'normal_request' cannot be resolved (requested in 'autouse_test.test_late_autouse_request_pre'). [missing-argname]
test_samples/autouse_test.py:31: error: 'late_autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_pre'. [fixture-arg-type]
test_samples/conftest.py:29: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_pre'. [fixture-arg-type]
test_samples/conftest.py:33: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_pre'. [fixture-arg-type]
test_samples/conftest.py:24: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_pre'. [fixture-arg-type]
test_samples/conftest.py:28: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_pre'. [fixture-arg-type]
test_samples/autouse_test.py:35: error: Argname 'normal_request' cannot be resolved (requested in 'autouse_test.test_late_autouse_request_post'). [missing-argname]
test_samples/autouse_test.py:31: error: 'late_autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_post'. [fixture-arg-type]
test_samples/conftest.py:29: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_post'. [fixture-arg-type]
test_samples/conftest.py:33: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_post'. [fixture-arg-type]
test_samples/conftest.py:24: error: 'autouse_request' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_post'. [fixture-arg-type]
test_samples/conftest.py:28: error: 'autouse_fixture' requests 'autouse_request' with type "str", but expects type "None". This happens when executing 'test_late_autouse_request_post'. [fixture-arg-type]
Found 15 errors in 2 files (checked 1 source file)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_samples/broken_conftest/broken_conftest_test.py:5: error: Test definitions must return "None", got "int". [test-return-type]
Found 1 error in 1 file (checked 1 source file)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Success: no issues found in 1 source file
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test_samples/broken_conftest/conftest.py:5: error: Marks cannot be applied to fixtures. [marked-fixture]
Found 1 error in 1 file (checked 1 source file)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test_samples/conftest.py:11: error: 'indirect_int_fixture' requests 'base_int_fixture' with type "str", but expects type "int". This happens when executing 'test_valid_indirect_int_fixture'. [fixture-arg-type]
test_samples/conftest.py:11: error: 'indirect_int_fixture' requests 'base_int_fixture' with type "str", but expects type "int". This happens when executing 'test_invalid_indirect_int_fixture'. [fixture-arg-type]
test_samples/conftest.py:25: error: Argname 'missing_argument' cannot be resolved (requested in 'different_file_fixture_test.test_requests_fixture_with_missing_argument'). [missing-argname]
test_samples/conftest.py:20: error: Argname 'missing_argument' cannot be resolved (requested in 'different_file_fixture_test.test_requests_fixture_with_missing_argument'). [missing-argname]
test_samples/different_file_fixture_test.py:24: error: Argname 'missed_fixture_decorator_in_another_file' cannot be resolved. [missing-argname]
test_samples/conftest.py:20: note: 'missed_fixture_decorator_in_another_file' is defined in 'conftest', but not marked as a fixture.
test_samples/conftest.py:15: note: 'missed_fixture_decorator_in_another_file' is defined in 'conftest', but not marked as a fixture.
test_samples/different_file_fixture_test.py:29: error: 'ordered_fixture1' requests 'ordered_fixture2' with type "Literal[3]", but expects type "None". This happens when executing 'test_ordered_case1'. [fixture-arg-type]
test_samples/different_file_fixture_test.py:29: error: 'ordered_fixture1' requests 'ordered_fixture2' with type "Literal[1]", but expects type "None". This happens when executing 'test_ordered_case2'. [fixture-arg-type]
test_samples/different_file_fixture_test.py:34: error: 'ordered_fixture2' requests 'ordered_fixture1' with type "Literal[0]", but expects type "None". This happens when executing 'test_ordered_case1'. [fixture-arg-type]
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
2.1.2