Pylint: unittest.assertRegex flagged as deprecated-method

Created on 11 Sep 2017  路  11Comments  路  Source: PyCQA/pylint

Steps to reproduce

```!python
import unittest

class ExampleTestCase(unittest.TestCase):

def test_regex(self):
    self.assertRegex("something", r".+")

````

Current behavior

pylint flags unittest.assertRegex as deprecated-method with Python 3.6.

Expected behavior

unittest.assertRegex is not deprecated in Python 3.6 and should not be flagged as deprecated. References:

pylint --version output

pylint 1.7.2,
astroid 1.5.3
Python 3.6.1 (default, Jun 29 2017, 01:17:46)
[GCC 4.2.1 Compatible FreeBSD Clang 3.8.0 (tags/RELEASE_380/final 262564)]
bug

Most helpful comment

@PCManticore care to re-open?

All 11 comments

I cannot reproduce this using the same pylint version, so not sure what exactly is going on here. Can you paste the exact output you get from pylint?

@PCManticore I'm able to reproduce with Django==1.11.5 and pylint==1.7.4. In check.py

"""d"""
from django.test import TestCase


class MyTestCase(TestCase):
    """d"""
    def test_something(self):
        """d"""
        self.assertRegex('string', 'other string')

    def test_something_else(self):
        """d"""
        self.assertRaisesRegex(ValueError, lambda: 'stuff')

In your shell

$ pylint --rcfile=pylint.rc check.py
************* Module check
W:  9, 8: Using deprecated method assertRegex() (deprecated-method)
W: 13, 8: Using deprecated method assertRaisesRegex() (deprecated-method)

-------------------------------------------------------------------
Your code has been rated at 6.67/10 (previous run: 10.00/10, -3.33)

could it be because of that ?

I ran into this issue as soon as I upgraded to Django 1.11, and a colleague too. Using pylint 1.8.1 and Python 3.5.

If I remove the block https://github.com/django/django/blob/1.11.5/django/test/testcases.py#L807-L811 the warnings disappear, letting think pylint would enter the if and record the aliases, even if the condition is false.

This change was indeed introduced in the 1.11 series https://github.com/django/django/commit/b5f0b3478dfcf0335f8ac2038d59f54b4a05f2a0

@PCManticore care to re-open?

Same issue with code migrated by 2to3, which switched us from self.assertRegexpMatches (no warning) to self.assertRegex:

************* Module XXX.tests.views.status
XXX/tests/views/status.py:13: [W1505(deprecated-method), StatusViewTestCase.test_status_view_context_normal] Using deprecated method assertRegex()

Still the case with Python 3.6, Django 1.11.15 and Pylint 2.1.1:

************* Module tests.core.actions.test_action
tests/core/actions/test_action.py:268: [W1505(deprecated-method), ActionTestCase.test_start_action.check_call] Using deprecated method assertRegex()
tests/core/actions/test_action.py:269: [W1505(deprecated-method), ActionTestCase.test_start_action.check_call] Using deprecated method assertRegex()
tests/core/actions/test_action.py:311: [W1505(deprecated-method), ActionTestCase.test_start_action.check_call] Using deprecated method assertRegex()
tests/core/actions/test_action.py:312: [W1505(deprecated-method), ActionTestCase.test_start_action.check_call] Using deprecated method assertRegex()

I pushed https://github.com/bors-ltd/testregex as a minimal project to reproduce the issue.

You just need to launch pylint on it (with a Python 3.x venv of course).

Yet another occurence. Using Ubuntu 18.04 with Python3.6.5

For Django it's definitely because of https://github.com/django/django/blob/1.11.5/django/test/testcases.py#L807-L811. I think we can make this check smarter by noticing how the method for defined, and if it's a version guard check, then we should not emit it.

This should be fixed in the master branch, if you can do give it a try and let me know if it works for you as well.

Was this page helpful?
0 / 5 - 0 ratings