Repository: joke2k/faker

Issue:
Error in running faker tests
Hi,

I use ```Python 3.5.2```.

I downloaded v0.7.3 archive from GH.

When I ran ``` python3 setup.py test```, I get a Fail; when I run ```python3 -m unittest -v faker.tests```, I get 'OK'

Did I do something the wrong way, since ipaddress is required for python 2.x or python 3.2?

Here's the full output

```
python3 setup.py test
running test
running egg_info
creating Faker.egg-info
writing top-level names to Faker.egg-info/top_level.txt
writing entry points to Faker.egg-info/entry_points.txt
writing requirements to Faker.egg-info/requires.txt
writing Faker.egg-info/PKG-INFO
writing dependency_links to Faker.egg-info/dependency_links.txt
writing manifest file 'Faker.egg-info/SOURCES.txt'
reading manifest file 'Faker.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.md'
writing manifest file 'Faker.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 78, in <module>
    'ipaddress',
  File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.5/site-packages/setuptools/command/test.py", line 159, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/usr/lib/python3.5/site-packages/setuptools/command/test.py", line 140, in with_project_on_sys_path
    func()
  File "/usr/lib/python3.5/site-packages/setuptools/command/test.py", line 180, in run_tests
    testRunner=self._resolve_as_ep(self.test_runner),
  File "/usr/lib/python3.5/unittest/main.py", line 93, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.5/unittest/main.py", line 140, in parseArgs
    self.createTests()
  File "/usr/lib/python3.5/unittest/main.py", line 147, in createTests
    self.module)
  File "/usr/lib/python3.5/unittest/loader.py", line 219, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.5/unittest/loader.py", line 219, in <listcomp>
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python3.5/unittest/loader.py", line 190, in loadTestsFromName
    return self.loadTestsFromModule(obj)
  File "/usr/lib/python3.5/site-packages/setuptools/command/test.py", line 30, in loadTestsFromModule
    for file in resource_listdir(module.__name__, ''):
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1170, in resource_listdir
    resource_name
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1466, in resource_listdir
    return self._listdir(self._fn(self.module_path, resource_name))
  File "/usr/lib/python3.5/site-packages/pkg_resources/__init__.py", line 1505, in _listdir
    "Can't perform this operation for unregistered loader type"
NotImplementedError: Can't perform this operation for unregistered loader type

```

```
python3 -m unittest -v faker.tests
test_add_provider_gives_priority_to_newly_added_provider (faker.tests.FactoryTestCase) ... ok
test_binary (faker.tests.FactoryTestCase) ... ok
test_command (faker.tests.FactoryTestCase) ... ok
test_command_custom_provider (faker.tests.FactoryTestCase) ... ok
test_date_time_between_dates (faker.tests.FactoryTestCase) ... ok
test_date_time_between_dates_with_tzinfo (faker.tests.FactoryTestCase) ... ok
test_date_time_this_period (faker.tests.FactoryTestCase) ... ok
test_date_time_this_period_with_tzinfo (faker.tests.FactoryTestCase) ... ok
test_datetime_safe (faker.tests.FactoryTestCase) ... ok
test_datetimes_with_and_without_tzinfo (faker.tests.FactoryTestCase) ... ok
test_documentor (faker.tests.FactoryTestCase) ... /tmp/faker-0.7.3/faker/documentor.py:51: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  argspec = inspect.getargspec(method)
ok
test_email (faker.tests.FactoryTestCase) ... ok
test_format_calls_formatter_on_provider (faker.tests.FactoryTestCase) ... ok
test_format_transfers_arguments_to_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_callable (faker.tests.FactoryTestCase) ... ok
test_get_formatter_returns_correct_formatter (faker.tests.FactoryTestCase) ... ok
test_get_formatter_throws_exception_on_incorrect_formatter (faker.tests.FactoryTestCase) ... ok
test_ipv4 (faker.tests.FactoryTestCase) ... ok
test_ipv6 (faker.tests.FactoryTestCase) ... ok
test_language_code (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format (faker.tests.FactoryTestCase) ... ok
test_magic_call_calls_format_with_arguments (faker.tests.FactoryTestCase) ... ok
test_no_words_paragraph (faker.tests.FactoryTestCase) ... ok
test_no_words_sentence (faker.tests.FactoryTestCase) ... ok
test_parse_returns_same_string_when_it_contains_no_curly_braces (faker.tests.FactoryTestCase) ... ok
test_parse_returns_string_with_tokens_replaced_by_formatters (faker.tests.FactoryTestCase) ... ok
test_password (faker.tests.FactoryTestCase) ... ok
test_prefix_suffix_always_string (faker.tests.FactoryTestCase) ... ok
test_random_element (faker.tests.FactoryTestCase) ... ok
test_random_pystr_characters (faker.tests.FactoryTestCase) ... ok
test_random_sample_unique (faker.tests.FactoryTestCase) ... ok
test_slugify (faker.tests.FactoryTestCase) ... ok
test_timezone_conversion (faker.tests.FactoryTestCase) ... ok
test_us_ssn_valid (faker.tests.FactoryTestCase) ... ok
test_get_random (faker.tests.GeneratorTestCase) ... ok
test_random_seed_doesnt_seed_system_random (faker.tests.GeneratorTestCase) ... ok
test_add_dicts (faker.tests.UtilsTestCase) ... ok
test_choice_distribution (faker.tests.UtilsTestCase) ... ok
test_find_available_locales (faker.tests.UtilsTestCase) ... ok
test_find_available_providers (faker.tests.UtilsTestCase) ... ok

----------------------------------------------------------------------
Ran 40 tests in 15.249s

OK

```


Discussion:
Error catched by Travis too
I tried to look into this but I couldn't figure out, and family commitments are preventing me from spending more time. If anyone can figure this out and submit a PR it would be great!
Hi @fcurella , I've done some experiments and found out remove `faker/tests/__init__.py:5` can run the tests via `python3 setup.py test` without problem. I also ran it without that line in python 2.7 and no problem occurred. I suspect it might has something to do with `__loader__ = None` overrides the behavior of built-in variable.

The line was added in commit [Fixed tests on PyPy3](https://github.com/joke2k/faker/commit/3e9ad63635138c3bfdcdaace7e76a7ae855342d4) so I'm not sure if removing that line will bring back the problem.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -51,9 +51,9 @@
     author_email='joke2k@gmail.com',
     url='https://github.com/joke2k/faker',
     license='MIT License',
-    packages=find_packages(exclude=("docs",)),
+    packages=find_packages(exclude=("docs", "tests",)),
     platforms=["any"],
-    test_suite='faker.tests',
+    test_suite='tests',
     zip_safe=zip_safe,
     install_requires=[
         "python-dateutil>=2.4",


Test patch:
diff --git a/faker/tests/__init__.py b/tests/__init__.py
similarity index 99%
rename from faker/tests/__init__.py
rename to tests/__init__.py
--- a/faker/tests/__init__.py
+++ b/tests/__init__.py
@@ -2,8 +2,6 @@
 
 from __future__ import unicode_literals
 
-__loader__ = None
-
 import datetime
 import json
 import os
@@ -227,7 +225,7 @@ def test_command_custom_provider(self):
         orig_stdout = sys.stdout
         try:
             sys.stdout = StringIO()
-            command = Command(['faker', 'foo', '-i', 'faker.tests.mymodule.en_US'])
+            command = Command(['faker', 'foo', '-i', 'tests.mymodule.en_US'])
             command.execute()
             assert sys.stdout.getvalue()
         finally:
diff --git a/faker/tests/en_GB/__init__.py b/tests/en_GB/__init__.py
similarity index 100%
rename from faker/tests/en_GB/__init__.py
rename to tests/en_GB/__init__.py
diff --git a/faker/tests/hr_HR/__init__.py b/tests/hr_HR/__init__.py
similarity index 100%
rename from faker/tests/hr_HR/__init__.py
rename to tests/hr_HR/__init__.py
diff --git a/faker/tests/ja_JP/__init__.py b/tests/ja_JP/__init__.py
similarity index 100%
rename from faker/tests/ja_JP/__init__.py
rename to tests/ja_JP/__init__.py
diff --git a/faker/tests/mymodule/__init__.py b/tests/mymodule/__init__.py
similarity index 100%
rename from faker/tests/mymodule/__init__.py
rename to tests/mymodule/__init__.py
diff --git a/faker/tests/mymodule/en_US/__init__.py b/tests/mymodule/en_US/__init__.py
similarity index 100%
rename from faker/tests/mymodule/en_US/__init__.py
rename to tests/mymodule/en_US/__init__.py
diff --git a/faker/tests/ne_np/__init__.py b/tests/ne_np/__init__.py
similarity index 100%
rename from faker/tests/ne_np/__init__.py
rename to tests/ne_np/__init__.py
diff --git a/faker/tests/no_NO/__init__.py b/tests/no_NO/__init__.py
similarity index 100%
rename from faker/tests/no_NO/__init__.py
rename to tests/no_NO/__init__.py
diff --git a/faker/tests/pt_BR/__init__.py b/tests/pt_BR/__init__.py
similarity index 100%
rename from faker/tests/pt_BR/__init__.py
rename to tests/pt_BR/__init__.py
diff --git a/faker/tests/random_state.json b/tests/random_state.json
similarity index 100%
rename from faker/tests/random_state.json
rename to tests/random_state.json
diff --git a/faker/tests/requirements.txt b/tests/requirements.txt
similarity index 100%
rename from faker/tests/requirements.txt
rename to tests/requirements.txt
diff --git a/faker/tests/zh_CN/__init__.py b/tests/zh_CN/__init__.py
similarity index 100%
rename from faker/tests/zh_CN/__init__.py
rename to tests/zh_CN/__init__.py