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

Commit 3699852

Browse files
committed
Fix crashes when using fixture + if + inline import
1 parent c34202f commit 3699852

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44
### Fixed
55
- Fix fixtures defined with `@pytest.yield_fixture` decorator still showing FP
6+
- Fix crashes when using fixture + if + inline import
67

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

pylint_pytest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,14 @@ def patched_add_message(self, msgid, line=None, node=None, args=None,
193193
# check W0613 unused-argument
194194
if msgid == 'unused-argument' and \
195195
_can_use_fixture(node.parent.parent) and \
196+
isinstance(node.parent, astroid.Arguments) and \
196197
node.name in self._pytest_fixtures:
197198
return
198199

199200
# check W0621 redefined-outer-name
200201
if msgid == 'redefined-outer-name' and \
201202
_can_use_fixture(node.parent.parent) and \
203+
isinstance(node.parent, astroid.Arguments) and \
202204
node.name in self._pytest_fixtures:
203205
return
204206

tests/base_tester.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _verify(self, module, msg_count, msg_id=None):
2424

2525
assert matched_count == msg_count
2626

27-
def run_test(self, msg_count, enable_plugin):
27+
def run_test(self, msg_count, enable_plugin, msg_id=None):
2828
# pylint: disable=protected-access
2929
file = sys._getframe(1).f_code.co_name.replace('test_', '', 1) + '.py'
3030
full_file_path = os.path.join(
@@ -41,6 +41,7 @@ def run_test(self, msg_count, enable_plugin):
4141
self._verify(
4242
module=module,
4343
msg_count=msg_count,
44+
msg_id=msg_id,
4445
)
4546
finally:
4647
if enable_plugin:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from conftest import conftest_fixture_func
2+
3+
4+
def test_using_conftest_fixture_attr():
5+
if True:
6+
from conftest import conftest_fixture_func

tests/test_regression.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from base_tester import BasePytestFixtureChecker
3+
4+
5+
class TestRegression(BasePytestFixtureChecker):
6+
'''Covering some behaviors that shouldn't get impacted by the plugin'''
7+
MSG_ID = 'regression'
8+
9+
@pytest.mark.parametrize('enable_plugin', [True, False])
10+
def test_import_twice(self, enable_plugin):
11+
'''catch a coding error when using fixture + if + inline import'''
12+
self.run_test(
13+
enable_plugin=enable_plugin,
14+
msg_count=2,
15+
msg_id='unused-import'
16+
)
17+
18+
self.run_test(
19+
enable_plugin=enable_plugin,
20+
msg_count=1,
21+
msg_id='redefined-outer-name'
22+
)

0 commit comments

Comments
 (0)