Make flake8 use built-in mock from unittest, if available (Python 3.4+)

This commit is contained in:
Kurt Mosiejczuk 2019-09-13 16:19:22 -04:00
parent 121ea4f056
commit 5faa1df46a
21 changed files with 84 additions and 21 deletions

View file

@ -1,4 +1,7 @@
"""Integration tests for the checker submodule.""" """Integration tests for the checker submodule."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -2,6 +2,9 @@
import json import json
import os import os
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -2,6 +2,9 @@
import argparse import argparse
import sys import sys
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Tests for the BaseFormatter object.""" """Tests for the BaseFormatter object."""
import argparse import argparse
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Tests for the Manager object for FileCheckers.""" """Tests for the Manager object for FileCheckers."""
import errno import errno
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -4,6 +4,9 @@ import configparser
import os import os
import sys import sys
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,5 +1,8 @@
"""Tests for our debugging module.""" """Tests for our debugging module."""
import entrypoints import entrypoints
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,4 +1,7 @@
"""Unit tests for the FileChecker class.""" """Unit tests for the FileChecker class."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -2,6 +2,9 @@
import ast import ast
import tokenize import tokenize
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,4 +1,7 @@
"""Tests for get_local_plugins.""" """Tests for get_local_plugins."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
from flake8.options import config from flake8.options import config

View file

@ -1,4 +1,7 @@
"""Tests around functionality in the git integration.""" """Tests around functionality in the git integration."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,4 +1,7 @@
"""Tests for Flake8's legacy API.""" """Tests for Flake8's legacy API."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Unit tests for flake8.options.config.MergedConfigParser.""" """Unit tests for flake8.options.config.MergedConfigParser."""
import os import os
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Unit tests for flake8.options.manager.Option.""" """Unit tests for flake8.options.manager.Option."""
import functools import functools
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -2,6 +2,9 @@
import argparse import argparse
import os import os
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Tests for flake8.plugins.manager.Plugin.""" """Tests for flake8.plugins.manager.Plugin."""
import argparse import argparse
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,4 +1,7 @@
"""Tests for flake8.plugins.manager.PluginManager.""" """Tests for flake8.plugins.manager.PluginManager."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
from flake8.plugins import manager from flake8.plugins import manager

View file

@ -1,4 +1,7 @@
"""Tests for flake8.plugins.manager.PluginTypeManager.""" """Tests for flake8.plugins.manager.PluginTypeManager."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Tests for the flake8.style_guide.StyleGuide class.""" """Tests for the flake8.style_guide.StyleGuide class."""
import argparse import argparse
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,6 +1,9 @@
"""Tests for flake8's utils module.""" """Tests for flake8's utils module."""
import os import os
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest

View file

@ -1,4 +1,7 @@
"""Tests for the flake8.style_guide.Violation class.""" """Tests for the flake8.style_guide.Violation class."""
try:
from unittest import mock
except (ImportError, AttributeError):
import mock import mock
import pytest import pytest