unittest.assertRegex flagged as deprecated-method #1653

Closed
lordgordon opened this Issue Sep 11, 2017 · 5 comments

Comments

Projects
None yet
4 participants

Steps to reproduce

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)]
Owner

PCManticore commented Sep 13, 2017

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?

m-vdb commented Oct 20, 2017

@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)

m-vdb commented Oct 20, 2017

could it be because of that ?

bors-ltd commented Jan 9, 2018

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 django/django@b5f0b34

m-vdb commented Jan 9, 2018

@PCManticore care to re-open?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment