Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 4bb09c9

Browse files
committed
Fix crashes when relatively importing fixtures
1 parent e783bd9 commit 4bb09c9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### Fixed
55
- Fix fixtures defined with `@pytest.yield_fixture` decorator still showing FP
66
- Fix crashes when using fixture + if + inline import
7+
- Fix crashes when relatively importing fixtures (`from ..conftest import fixture`)
78

89
## [0.1.1] - 2020-05-19
910
### Fixed

pylint_pytest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ def _can_use_fixture(function):
6464

6565
def _is_same_module(fixtures, import_node, fixture_name):
6666
'''Comparing pytest fixture node with astroid.ImportFrom'''
67-
for fixture in fixtures[fixture_name]:
68-
for import_from in import_node.root().globals[fixture_name]:
69-
if inspect.getmodule(fixture.func).__file__ == \
70-
import_from.parent.import_module(import_from.modname).file:
71-
return True
72-
67+
try:
68+
for fixture in fixtures[fixture_name]:
69+
for import_from in import_node.root().globals[fixture_name]:
70+
if inspect.getmodule(fixture.func).__file__ == \
71+
import_from.parent.import_module(import_from.modname,
72+
False,
73+
import_from.level).file:
74+
return True
75+
except: # pylint: disable=bare-except
76+
pass
7377
return False
7478

7579

0 commit comments

Comments
 (0)