Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest.assertRegex flagged as deprecated-method #1653

Closed
lordgordon opened this issue Sep 11, 2017 · 11 comments
Closed

unittest.assertRegex flagged as deprecated-method #1653

lordgordon opened this issue Sep 11, 2017 · 11 comments
Labels

Comments

@lordgordon
Copy link

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)]
@PCManticore
Copy link
Contributor

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
Copy link

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
Copy link

m-vdb commented Oct 20, 2017

could it be because of that ?

@bors-ltd
Copy link

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
Copy link

m-vdb commented Jan 9, 2018

@PCManticore care to re-open?

@olivierlefloch
Copy link

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

@bors-ltd
Copy link

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

@bors-ltd
Copy link

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

@SteffenKockel
Copy link

Yet another occurence. Using Ubuntu 18.04 with Python3.6.5

@PCManticore
Copy link
Contributor

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.

@PCManticore
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants