testing-cabal / mock

The Python mock library
https://docs.python.org/dev/library/unittest.mock.html
BSD 2-Clause "Simplified" License
536 stars 107 forks source link

4.0.3: pytest is failing #498

Closed kloczek closed 3 years ago

kloczek commented 3 years ago

What versions are you using?

What happened? I'm trying to package your module as rpm packag. So I'm using typical in such case build, install and test cycle used on building package from non-root account:

May I ask for help because few units are failing:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-mock-4.0.3-2.1.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-mock-4.0.3-2.1.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --cov
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=715225644
rootdir: /home/tkloczko/rpmbuild/BUILD/mock-4.0.3, configfile: setup.cfg
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, pyfakefs-4.5.0, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, checkdocs-2.7.1, anyio-3.3.0, Faker-8.11.0, asyncio-0.15.1, trio-0.7.0, httpbin-1.0.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0
collected 2 items / 9 errors

================================================================================== ERRORS ==================================================================================
_________________________________________________________________ ERROR collecting mock/tests/testasync.py _________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testasync.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_______________________________________________________________ ERROR collecting mock/tests/testcallable.py ________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testcallable.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)
E   ModuleNotFoundError: No module named 'mock.tests'
________________________________________________________________ ERROR collecting mock/tests/testhelpers.py ________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testhelpers.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_____________________________________________________________ ERROR collecting mock/tests/testmagicmethods.py ______________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testmagicmethods.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_________________________________________________________________ ERROR collecting mock/tests/testmock.py __________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testmock.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_________________________________________________________________ ERROR collecting mock/tests/testpatch.py _________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testpatch.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_______________________________________________________________ ERROR collecting mock/tests/testsealable.py ________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testsealable.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_______________________________________________________________ ERROR collecting mock/tests/testsentinel.py ________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testsentinel.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)
E   ModuleNotFoundError: No module named 'mock.tests'
_________________________________________________________________ ERROR collecting mock/tests/testwith.py __________________________________________________________________
ImportError while importing test module '/home/tkloczko/rpmbuild/BUILD/mock-4.0.3/mock/tests/testwith.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)
E   ModuleNotFoundError: No module named 'mock.tests'
========================================================================= short test summary info ==========================================================================
ERROR mock/tests/testasync.py
ERROR mock/tests/testcallable.py
ERROR mock/tests/testhelpers.py
ERROR mock/tests/testmagicmethods.py
ERROR mock/tests/testmock.py
ERROR mock/tests/testpatch.py
ERROR mock/tests/testsealable.py
ERROR mock/tests/testsentinel.py
ERROR mock/tests/testwith.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 9 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================ 9 errors in 0.35s =============================================================================
pytest-xprocess reminder::Be sure to terminate the started process by running 'pytest --xkill' if you have not explicitly done so in your fixture with 'xprocess.getinfo(<process_name>).terminate()'.

On first look it looks like it fails because it cannot find mock.tests module which is not installed and looks like mock test suite assumes that it will be testing not what has been installed but source tree where is mock.tests.

cjw296 commented 3 years ago

Correct: the tests are not included in the distribution, so to run them you need to use a source checkout. This is intentional and is unlikely to change.

kloczek commented 3 years ago

But I'm not using sdist tar ball.

cjw296 commented 3 years ago

I suspect "setup.py install --root </install/prefix>" is having the same effect. The CircleCI run does a pip install -e .[dev] from a source checkout, and the tests are run from within the source checkout.

If you want the same behaviour, please use the same methods.

If you want to use a different set of methods, then I'm afraid you'll need to figure out why it's not working for you.

kloczek commented 3 years ago

Issue is that in your CI looks like you are doing everything from root in /usr/local when I need to do that from non-root account in </install/prefix> to be able use that base directory to collect all files to assemble at the end package. To be honest I have art the moment almost 600 packaged modules and I see first-time ever module which (so far) is not possible to build, install and test from non root account. I'm using setuptools to install stuff in +99% of all those packages

[tkloczko@barrel SPECS]$ grep ^%py3_install -lw python-* | wc -l; ls -1 python-* | wc -l
582
586

and none of those packages has problems like I found in mock

kloczek commented 3 years ago

BTW. setuptools build and isnstall shows some warnings

[tkloczko@barrel mock-4.0.3]$ python3 setup.py build
/usr/lib/python3.8/site-packages/setuptools/dist.py:697: UserWarning: Usage of dash-separated 'home-page' will not be supported in future versions. Please use the underscore name 'home_page' instead
  warnings.warn(
/usr/lib/python3.8/site-packages/setuptools/dist.py:697: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
  warnings.warn(
/usr/lib/python3.8/site-packages/setuptools/dist.py:697: UserWarning: Usage of dash-separated 'author-email' will not be supported in future versions. Please use the underscore name 'author_email' instead
  warnings.warn(
running build
running build_py