13.3.5: pytest is failing because it uses no longer maintained `random2` module
- Faker version: 13.3.5
- OS: Linux x86/64
Brief summary of the issue
Looks like pytest is failing because test suite still is using outdated random2 module which was never updated for python 3.x).
Steps to reproduce
I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.
-
python3 -sBm build -w --no-isolation - because I'm calling
buildwith--no-isolationI'm using during all processes only locally installed modules - install .whl file in </install/prefix>
- run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
Expected behavior
pytest should not fail.
Actual behavior
Here is pytest output:
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -q
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/faker-13.3.5, configfile: setup.cfg
plugins: Faker-13.3.5
collected 1491 items / 1 error
================================================================================== ERRORS ==================================================================================
_______________________________________________________________ ERROR collecting tests/providers/test_ssn.py _______________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/faker-13.3.5/tests/providers/test_ssn.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/providers/test_ssn.py:11: in <module>
import random2
E ModuleNotFoundError: No module named 'random2'
============================================================================= warnings summary =============================================================================
../../BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages/faker/providers/person/fr_QC/__init__.py:10
/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages/faker/providers/person/fr_QC/__init__.py:10: UserWarning: fr_QC locale is deprecated. Please use fr_CA.
warnings.warn("fr_QC locale is deprecated. Please use fr_CA.")
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= short test summary info ==========================================================================
ERROR tests/providers/test_ssn.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
======================================================================= 1 warning, 1 error in 10.95s =======================================================================
Jus tchecked and I've alredy reported that https://github.com/joke2k/faker/issues/1454. Ticket has been closed without fixing the issue 😞
pytest executed with that single file added to ignore list howevert it shows the same warninngs about fr_QC locale as sphinx shows
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -q --ignore tests/providers/test_ssn.py
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/faker-13.3.5, configfile: setup.cfg
plugins: Faker-13.3.5
collected 1491 items
tests/test_decode.py ....................................................................................................................................... [ 9%]
tests/test_factory.py ....................... [ 10%]
tests/test_generator.py .................. [ 11%]
tests/test_providers_formats.py ................................................................................. [ 17%]
tests/test_proxy.py ............................ [ 19%]
tests/test_unique.py ..... [ 19%]
tests/providers/__init__.py ............................................ [ 22%]
tests/providers/test_address.py ..........................................................s......................................................................... [ 31%]
.................................................................................................................................................................... [ 42%]
........................ [ 43%]
tests/providers/test_automotive.py ..................................... [ 46%]
tests/providers/test_bank.py .................................................... [ 49%]
tests/providers/test_barcode.py ............................................. [ 52%]
tests/providers/test_color.py ................................. [ 55%]
tests/providers/test_company.py ................................................................ [ 59%]
tests/providers/test_credit_card.py .................. [ 60%]
tests/providers/test_currency.py .................................... [ 62%]
tests/providers/test_date_time.py ........................................................................................... [ 69%]
tests/providers/test_dynamic.py ..... [ 69%]
tests/providers/test_file.py ... [ 69%]
tests/providers/test_geo.py ............................ [ 71%]
tests/providers/test_internet.py ................................................................... [ 75%]
tests/providers/test_isbn.py ...... [ 76%]
tests/providers/test_job.py ............... [ 77%]
tests/providers/test_lorem.py .................................................................... [ 81%]
tests/providers/test_misc.py ........................................... [ 84%]
tests/providers/test_person.py ............................................................... [ 89%]
tests/providers/test_phone_number.py ....................................................... [ 92%]
tests/providers/test_profile.py .. [ 92%]
tests/providers/test_python.py .............s........................................ [ 96%]
tests/providers/test_user_agent.py ... [ 96%]
tests/pytest/test_autouse_faker_locale.py .. [ 96%]
tests/pytest/test_autouse_faker_seed.py .. [ 96%]
tests/pytest/test_manual_injection.py .... [ 97%]
tests/pytest/test_unique_clear.py . [ 97%]
tests/pytest/session_overrides/session_locale/test_autouse_faker_locale.py ss [ 97%]
tests/pytest/session_overrides/session_locale/test_autouse_faker_seed.py ss [ 97%]
tests/pytest/session_overrides/session_locale/test_manual_injection.py ssss [ 97%]
tests/sphinx/test_docstring.py ............ [ 98%]
tests/sphinx/test_validator.py ........... [ 99%]
tests/utils/test_utils.py ......... [100%]
============================================================================= warnings summary =============================================================================
../../BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages/faker/providers/person/fr_QC/__init__.py:10
tests/test_factory.py::FactoryTestCase::test_documentor
tests/test_providers_formats.py::test_no_invalid_formats[fr_QC]
/home/tkloczko/rpmbuild/BUILDROOT/python-faker-13.3.5-2.fc35.x86_64/usr/lib/python3.8/site-packages/faker/providers/person/fr_QC/__init__.py:10: UserWarning: fr_QC locale is deprecated. Please use fr_CA.
warnings.warn("fr_QC locale is deprecated. Please use fr_CA.")
tests/test_factory.py::FactoryTestCase::test_documentor
/usr/lib/python3.8/site-packages/dateutil/zoneinfo/__init__.py:26: UserWarning: I/O error(2): No such file or directory
warnings.warn("I/O error({0}): {1}".format(e.errno, e.strerror))
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/providers/test_address.py:474: could not import 'ukpostcodeparser.parser': No module named 'ukpostcodeparser'
SKIPPED [1] tests/providers/test_python.py:219: Only relevant for Python 3.10 and later.
SKIPPED [2] tests/pytest/session_overrides/session_locale/test_autouse_faker_locale.py: This test is skipped by default since it depends on changes in the behavior of session-scoped fixtures. Use a separate pytest run for tests like this with the "--exclusive-faker-session" flag specified.
SKIPPED [2] tests/pytest/session_overrides/session_locale/test_autouse_faker_seed.py: This test is skipped by default since it depends on changes in the behavior of session-scoped fixtures. Use a separate pytest run for tests like this with the "--exclusive-faker-session" flag specified.
SKIPPED [4] tests/pytest/session_overrides/session_locale/test_manual_injection.py: This test is skipped by default since it depends on changes in the behavior of session-scoped fixtures. Use a separate pytest run for tests like this with the "--exclusive-faker-session" flag specified.
============================================================== 1481 passed, 10 skipped, 4 warnings in 57.89s ===============================================================
@kloczek would adding random2 to tests_require in setup.py fix your issue?
I'm not using setu.py. As I wrote on top of the ticket I'm using pep517 build procedure.
Using already setup py is marked in setuptools as deprecated. You should move to pyproject.toml + setup.cfg.
And no .. hardcoding anywhere build dependencies to use long time not maintained module which was never updated for python 3.x is not good idea.
If you have the time to work on it, I'll be more than happy to move to pyproject.toml and setup.fcg
Issue is that I still have long queue packages to update/do from scratch 😞 .. however you can always count on me to report every possible small issue which I'm able to spot on packaging or test any even preliminary patch in my build env 😃 (best as PR or downloadable over URL patches because it is very easy to plug into my build procedures). Sorry .. If it is still unresolved just please keep that thicket opened. In my build procedures I'm ignoring that file so that issue is not urgent for me 😄, and I fully understand that other people may have more important things to do.
I've created https://github.com/joke2k/faker/issues/1636 to keep track of the efforts re: pakaging
This issue is stale because it has been open for 30 days with no activity.
Any progress? 🤔
This issue is stale because it has been open for 30 days with no activity.
Gentle ping ..
@kloczek We can't switch packaging system (see #1636), so I have no idea how to fix your issues. Suggestions are welcome
Having a quick look at this, it seems like it is related to the seeds leading to a different behavior for random and random2. Taking tests.providers.test_ssn.TestEtEE.test_ssn as an example, using the following code will generate 46808220410 with random and 44010044206 with random2, although using the same seed:
self.fake.random = random.Random()
self.fake.seed_instance(0)
print(self.fake.ssn())
self.fake.random = random2.Random()
self.fake.seed_instance(0)
print(self.fake.ssn())
We either have to replace the target value or find the correct seed for random to generate the same strings. As I am not familiar enough with the SSN providers, fixing this myself might lead to wrong results. By the way: When we are already seeding the generator, shouldn't we be able to match the exact result instead?
The relevant changes have been #920 by @fcurella and #962 by @darrylwhiting.
To fix tests.providers.test_ssn.TestEtEE.test_ssn, it seems like we need the seeds 46818848 and 17059281 (determined by brute-forcing them, without using the freezegun decorator).
To add on this: I had another look at tests.providers.test_ssn.TestEnUS.test_invalid_ssn. Except for the second generated number, I have been able to brute-force the corresponding seeds. When checking this, I discovered that the documented numbers in the comment there are indeed not always correct - the first and the last one are correct, the middle one appears to be completely wrong and the remaining two have a last digit which is off by one.
Nevertheless, as the generated seeds are quite large, I suggest to adapt the tests for the numbers generated with random instead of random2 - maybe doing exact checks for the numbers as well due to using fixed seeds anyway. If there already is some change there, dropping the freezegun decorators inside this test file might be valid as well.
Thank you @stefan6419846. I've removed random2 from the tests