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

1.1.1: pytest is failing #5

Closed
kloczek opened this issue Apr 21, 2023 · 5 comments · Fixed by #6
Closed

1.1.1: pytest is failing #5

kloczek opened this issue Apr 21, 2023 · 5 comments · Fixed by #6

Comments

@kloczek
Copy link

kloczek commented Apr 21, 2023

I'm packaging 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 build with --no-isolation I'm using during all processes only locally installed modules
  • install .whl file in </install/prefix> using 'installer` module
  • run pytest with $PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>
  • build is performed in env which is cut off from access to the public network (pytest is executed with -m "not network")

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.16, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/sphinx-code-include-1.1.1
configfile: setup.cfg
testpaths: tests
collected 37 items

tests/integrations/test_code_include.py .FFFFF                                                                                                                                        [ 16%]
tests/unittests/test_code_include.py .................                                                                                                                                [ 62%]
tests/unittests/test_tag.py ..............                                                                                                                                            [100%]

========================================================================================= FAILURES ==========================================================================================
___________________________________________________________________________________ SourceReader.test_url ___________________________________________________________________________________
tests/integrations/test_code_include.py:82: in test_url
    _get_app_inventory.return_value = common.load_cache_from_url(path)
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:33: in __call__
    return self[args]
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:36: in __missing__
    ret = self[key] = self.function(*key)
tests/common.py:137: in load_cache_from_url
    return intersphinx.fetch_inventory(MockApplication(), "", url)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:163: in fetch_inventory
    f = _read_from_url(inv, config=app.config)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:119: in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:71: in get
    headers.setdefault('User-Agent', _get_user_agent(config))
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:53: in _get_user_agent
    if config.user_agent:
E   AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has no attribute 'user_agent'")
________________________________________________________________________________ InventoryReader.test_class _________________________________________________________________________________
tests/integrations/test_code_include.py:407: in test_class
    self._test_import(content, expected)  # pylint: disable=no-value-for-parameter
/usr/lib64/python3.8/unittest/mock.py:1325: in patched
    return func(*newargs, **newkeywargs)
tests/integrations/test_code_include.py:362: in _test_import
    _get_app_inventory.return_value = common.load_cache_from_url(path)
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:33: in __call__
    return self[args]
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:36: in __missing__
    ret = self[key] = self.function(*key)
tests/common.py:137: in load_cache_from_url
    return intersphinx.fetch_inventory(MockApplication(), "", url)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:163: in fetch_inventory
    f = _read_from_url(inv, config=app.config)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:119: in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:71: in get
    headers.setdefault('User-Agent', _get_user_agent(config))
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:53: in _get_user_agent
    if config.user_agent:
E   AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has no attribute 'user_agent'")
_______________________________________________________________________________ InventoryReader.test_function _______________________________________________________________________________
tests/integrations/test_code_include.py:428: in test_function
    self._test_import(content, expected)  # pylint: disable=no-value-for-parameter
/usr/lib64/python3.8/unittest/mock.py:1325: in patched
    return func(*newargs, **newkeywargs)
tests/integrations/test_code_include.py:362: in _test_import
    _get_app_inventory.return_value = common.load_cache_from_url(path)
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:33: in __call__
    return self[args]
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:36: in __missing__
    ret = self[key] = self.function(*key)
tests/common.py:137: in load_cache_from_url
    return intersphinx.fetch_inventory(MockApplication(), "", url)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:163: in fetch_inventory
    f = _read_from_url(inv, config=app.config)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:119: in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:71: in get
    headers.setdefault('User-Agent', _get_user_agent(config))
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:53: in _get_user_agent
    if config.user_agent:
E   AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has no attribute 'user_agent'")
________________________________________________________________________________ InventoryReader.test_method ________________________________________________________________________________
tests/integrations/test_code_include.py:459: in test_method
    self._test_import(content, expected)  # pylint: disable=no-value-for-parameter
/usr/lib64/python3.8/unittest/mock.py:1325: in patched
    return func(*newargs, **newkeywargs)
tests/integrations/test_code_include.py:362: in _test_import
    _get_app_inventory.return_value = common.load_cache_from_url(path)
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:33: in __call__
    return self[args]
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:36: in __missing__
    ret = self[key] = self.function(*key)
tests/common.py:137: in load_cache_from_url
    return intersphinx.fetch_inventory(MockApplication(), "", url)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:163: in fetch_inventory
    f = _read_from_url(inv, config=app.config)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:119: in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:71: in get
    headers.setdefault('User-Agent', _get_user_agent(config))
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:53: in _get_user_agent
    if config.user_agent:
E   AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has no attribute 'user_agent'")
________________________________________________________________________________ InventoryReader.test_module ________________________________________________________________________________
tests/integrations/test_code_include.py:699: in test_module
    self._test_import(content, expected)  # pylint: disable=no-value-for-parameter
/usr/lib64/python3.8/unittest/mock.py:1325: in patched
    return func(*newargs, **newkeywargs)
tests/integrations/test_code_include.py:362: in _test_import
    _get_app_inventory.return_value = common.load_cache_from_url(path)
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:33: in __call__
    return self[args]
../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/helper.py:36: in __missing__
    ret = self[key] = self.function(*key)
tests/common.py:137: in load_cache_from_url
    return intersphinx.fetch_inventory(MockApplication(), "", url)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:163: in fetch_inventory
    f = _read_from_url(inv, config=app.config)
/usr/lib/python3.8/site-packages/sphinx/ext/intersphinx.py:119: in _read_from_url
    r = requests.get(url, stream=True, config=config, timeout=config.intersphinx_timeout)
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:71: in get
    headers.setdefault('User-Agent', _get_user_agent(config))
/usr/lib/python3.8/site-packages/sphinx/util/requests.py:53: in _get_user_agent
    if config.user_agent:
E   AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has no attribute 'user_agent'")
===================================================================================== warnings summary ======================================================================================
../../../../../usr/lib/python3.8/site-packages/_pytest/config/__init__.py:1248
  /usr/lib/python3.8/site-packages/_pytest/config/__init__.py:1248: PytestRemovedIn8Warning: The --strict option is deprecated, use --strict-markers instead.
    self.issue_config_time_warning(

../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/extension.py:16
  /home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/extension.py:16: DeprecationWarning: The frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
    _SETTINGS = frontend.OptionParser().get_default_values()

../../../../../usr/lib64/python3.8/optparse.py:1000: 50 warnings
  /usr/lib64/python3.8/optparse.py:1000: DeprecationWarning: The frontend.Option class will be removed in Docutils 0.21 or later.
    option = self.option_class(*args, **kwargs)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
FAILED tests/integrations/test_code_include.py::SourceReader::test_url - AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has ...
FAILED tests/integrations/test_code_include.py::InventoryReader::test_class - AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has ...
FAILED tests/integrations/test_code_include.py::InventoryReader::test_function - AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has ...
FAILED tests/integrations/test_code_include.py::InventoryReader::test_method - AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has ...
FAILED tests/integrations/test_code_include.py::InventoryReader::test_module - AttributeError: ('intersphinx inventory %r not fetchable due to %s: %s', 'https://ways.readthedocs.io/en/latest/objects.inv', <class 'AttributeError'>, "'MockConfiguration' object has ...
========================================================================= 5 failed, 32 passed, 52 warnings in 1.45s =========================================================================

Here is list of installed modules in build env

Package                       Version
----------------------------- -----------------
alabaster                     0.7.13
Babel                         2.12.1
beautifulsoup4                4.12.0
build                         0.10.0
charset-normalizer            3.1.0
distro                        1.8.0
docutils                      0.19
exceptiongroup                1.0.0
gpg                           1.19.0
idna                          3.4
imagesize                     1.4.1
importlib-metadata            6.5.0
iniconfig                     2.0.0
installer                     0.7.0
Jinja2                        3.1.2
libcomps                      0.1.19
MarkupSafe                    2.1.2
packaging                     23.1
pluggy                        1.0.0
Pygments                      2.15.1
pyproject_hooks               1.0.0
pytest                        7.3.1
python-dateutil               2.8.2
pytz                          2023.2
requests                      2.28.2
setuptools                    67.6.1
six                           1.16.0
snowballstemmer               2.2.0
soupsieve                     2.4.1
Sphinx                        6.1.3
sphinxcontrib-applehelp       1.0.4
sphinxcontrib-devhelp         1.0.2.dev20230415
sphinxcontrib-htmlhelp        2.0.0
sphinxcontrib-jsmath          1.0.1.dev20230415
sphinxcontrib-qthelp          1.0.3.dev20230415
sphinxcontrib-serializinghtml 1.1.5
tomli                         2.0.1
urllib3                       1.26.15
wheel                         0.40.0
zipp                          3.15.0
@ColinKennedy
Copy link
Owner

Thanks for this report. It's worth mentioning a few things. I haven't touched this code in forever so the integration tests could very well could be breaking. I'll double check that. Either way, I think it'd be good to add @unittest.skipIf for tests/integrations/ so the tests that require Internet access pass silently.

That said, this repository is simply not set up for pytest so I make no guarantees on pytest running. This repository uses standard unittest calls that ship with Python and tox handles the bootstrapping.

Are you calling pytest yourself? If so, I recommend to instead tox, as documented. If you are calling something else which then calls pytest indirectly then we can talk about it.

Anyway, I'll give this a shot over the weekend and let you know how it goes.

@kloczek
Copy link
Author

kloczek commented Apr 21, 2023

Thank you 👍
No problem 😄

And tox: I'm running wole build in isolated env which has installaled only what is required during build, install and test so running tox does not make to much sense. Other thing is that use pytest instead tox allows me to perform mass tests across all packages with pytjon modules (currently I have +1.1k such packages) and alter testing procedure by py install in build env additional pytest extension adn/or change rpm %pytest macro definition to execute pytest with some addional params.
tox does not provide such level of flexibility 😋

@ColinKennedy
Copy link
Owner

All the same, the fix seems to be trivial and is available for review over at #6. Please try that branch out and let me know if you're still getting the error.

@kloczek
Copy link
Author

kloczek commented Apr 23, 2023

Just tested that and indeed it fixed the issue.
Thank you 👍

However I see as well some warnings as well

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -m 'not network'
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.16, pytest-7.3.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/sphinx-code-include-1.1.1
configfile: setup.cfg
testpaths: tests
plugins: Faker-18.4.0
collected 37 items

tests/integrations/test_code_include.py ......                                                                                                                                        [ 16%]
tests/unittests/test_code_include.py .................                                                                                                                                [ 62%]
tests/unittests/test_tag.py ..............                                                                                                                                            [100%]

===================================================================================== warnings summary ======================================================================================
../../../../../usr/lib/python3.8/site-packages/_pytest/config/__init__.py:1248
  /usr/lib/python3.8/site-packages/_pytest/config/__init__.py:1248: PytestRemovedIn8Warning: The --strict option is deprecated, use --strict-markers instead.
    self.issue_config_time_warning(

../../BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/extension.py:16
  /home/tkloczko/rpmbuild/BUILDROOT/python-sphinx-code-include-1.1.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/code_include/extension.py:16: DeprecationWarning: The frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
    _SETTINGS = frontend.OptionParser().get_default_values()

../../../../../usr/lib64/python3.8/optparse.py:1000: 50 warnings
  /usr/lib64/python3.8/optparse.py:1000: DeprecationWarning: The frontend.Option class will be removed in Docutils 0.21 or later.
    option = self.option_class(*args, **kwargs)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================== 37 passed, 52 warnings in 4.81s ==============================================================================

@ColinKennedy
Copy link
Owner

ColinKennedy commented Apr 27, 2023

Oh okay. Well luckily that line is unused so it can be removed. Thanks for your issue and please let me know if you face any more problems!

ColinKennedy added a commit that referenced this issue Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants