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

8.11.1: pytest fails #750

Open
kloczek opened this issue Jan 14, 2024 · 7 comments
Open

8.11.1: pytest fails #750

kloczek opened this issue Jan 14, 2024 · 7 comments
Labels
type: twilio enhancement feature request on Twilio's roadmap

Comments

@kloczek
Copy link

kloczek commented Jan 14, 2024

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-twilio-8.11.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.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.18, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/tkloczko/rpmbuild/BUILD/twilio-python-8.11.1
collected 537 items / 2 errors

========================================================================================== ERRORS ===========================================================================================
______________________________________________________________________ ERROR collecting tests/cluster/test_webhook.py _______________________________________________________________________
tests/cluster/test_webhook.py:7: in <module>
    class RequestHandler(BaseHTTPRequestHandler):
tests/cluster/test_webhook.py:9: in RequestHandler
    validator = RequestValidator(os.environ["TWILIO_AUTH_TOKEN"])
/usr/lib64/python3.8/os.py:675: in __getitem__
    raise KeyError(key) from None
E   KeyError: 'TWILIO_AUTH_TOKEN'
_________________________________________________________________ ERROR collecting twilio/rest/events/v1/sink/sink_test.py __________________________________________________________________
import file mismatch:
imported module 'twilio.rest.events.v1.sink.sink_test' has this __file__ attribute:
  /home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86_64/usr/lib/python3.8/site-packages/twilio/rest/events/v1/sink/sink_test.py
which is not the same as the test file we want to collect:
  /home/tkloczko/rpmbuild/BUILD/twilio-python-8.11.1/twilio/rest/events/v1/sink/sink_test.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules
===================================================================================== warnings summary ======================================================================================
tests/unit/base/test_version.py:7
  /home/tkloczko/rpmbuild/BUILD/twilio-python-8.11.1/tests/unit/base/test_version.py:7: PytestCollectionWarning: cannot collect test class 'TestPage' because it has a __init__ constructor (from: tests/unit/base/test_version.py)
    class TestPage(Page):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
ERROR tests/cluster/test_webhook.py - KeyError: 'TWILIO_AUTH_TOKEN'
ERROR twilio/rest/events/v1/sink/sink_test.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================================== 1 warning, 2 errors in 1.20s ================================================================================
List of installed modules in build env:
Package                       Version
----------------------------- -------
aiohttp                       3.9.1
aiohttp-retry                 2.8.3
aiosignal                     1.3.1
aiounittest                   1.4.2
alabaster                     0.7.16
asgiref                       3.7.2
async-timeout                 4.0.3
attrs                         23.2.0
Babel                         2.14.0
backports.zoneinfo            0.2.1
build                         1.0.3
cffi                          1.16.0
charset-normalizer            3.3.2
commonmark                    0.9.1
cppclean                      0.13
cryptography                  41.0.5
distro                        1.9.0
Django                        4.2.6
dnf                           4.18.2
docutils                      0.20.1
exceptiongroup                1.1.3
frozenlist                    1.4.1
gpg                           1.23.2
idna                          3.6
imagesize                     1.4.1
importlib-metadata            7.0.1
iniconfig                     2.0.0
installer                     0.7.0
Jinja2                        3.1.3
libdnf                        0.72.0
MarkupSafe                    2.1.3
mock                          5.1.0
multidict                     6.0.4
packaging                     23.2
pluggy                        1.3.0
ply                           3.11
pycparser                     2.21
Pygments                      2.17.2
PyJWT                         2.8.0
pyngrok                       7.0.5
pyproject_hooks               1.0.0
pytest                        7.4.4
python-dateutil               2.8.2
pytz                          2023.3
PyYAML                        6.0.1
recommonmark                  0.7.1
requests                      2.31.0
setuptools                    69.0.3
six                           1.16.0
snowballstemmer               2.2.0
Sphinx                        7.1.2
sphinxcontrib-applehelp       1.0.4
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.10
sqlparse                      0.4.4
tomli                         2.0.1
typing_extensions             4.9.0
urllib3                       1.26.18
wheel                         0.42.0
wrapt                         1.16.0
yarl                          1.9.2
zipp                          3.17.0

Please let me know if you need more details or want me to perform some diagnostics.

@kloczek kloczek changed the title 8.11.1: pytest fails because missing twilio.rest.autopilot.AutopilotBase 8.11.1: pytest fails Jan 14, 2024
@kloczek
Copy link
Author

kloczek commented Jan 14, 2024

After add tests/cluster/test_webhook.py and twilio/rest/events/v1/sink/sink_test.py to --ignore list
+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra -m 'not network' --ignore tests/cluster/test_webhook.py --ignore twilio/rest/events/v1/sink/sink_test.py
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.8.18, pytest-7.4.4, pluggy-1.3.0
rootdir: /home/tkloczko/rpmbuild/BUILD/twilio-python-8.11.1
collected 537 items

tests/cluster/test_cluster.py FFFFFFF                                                                                                                                                 [  1%]
tests/unit/test_request_validator.py ..........                                                                                                                                       [  3%]
tests/unit/base/test_deprecation.py ..                                                                                                                                                [  3%]
tests/unit/base/test_deserialize.py ....................                                                                                                                              [  7%]
tests/unit/base/test_serialize.py ....................                                                                                                                                [ 10%]
tests/unit/base/test_version.py ....                                                                                                                                                  [ 11%]
tests/unit/http/test_async_http_client.py .......                                                                                                                                     [ 13%]
tests/unit/http/test_http_client.py ..............                                                                                                                                    [ 15%]
tests/unit/http/test_validation_client.py ..........                                                                                                                                  [ 17%]
tests/unit/jwt/test_access_token.py ..................                                                                                                                                [ 20%]
tests/unit/jwt/test_client.py ............                                                                                                                                            [ 23%]
tests/unit/jwt/test_client_validation.py ..........                                                                                                                                   [ 24%]
tests/unit/jwt/test_jwt.py ....................                                                                                                                                       [ 28%]
tests/unit/jwt/test_task_router.py .....................                                                                                                                              [ 32%]
tests/unit/rest/test_client.py ..............                                                                                                                                         [ 35%]
tests/unit/twiml/test_messaging_response.py ............................................................................                                                              [ 49%]
tests/unit/twiml/test_voice_response.py ............................................................................................................................................. [ 75%]
...................................................................................................................................                                                   [100%]

========================================================================================= FAILURES ==========================================================================================
_________________________________________________________ ClusterTest.test_allow_special_characters_for_friendly_and_identity_name __________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_allow_special_characters_for_friendly_and_identity_name>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...T': 'tests/cluster/test_cluster.py::ClusterTest::test_allow_special_characters_for_friendly_and_identity_name (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
___________________________________________________________________________ ClusterTest.test_calling_twiml_object ___________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_calling_twiml_object>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...sr/bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_calling_twiml_object (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
___________________________________________________________________________ ClusterTest.test_calling_twiml_string ___________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_calling_twiml_string>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...sr/bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_calling_twiml_string (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
_________________________________________________________________________ ClusterTest.test_list_an_incoming_number __________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_list_an_incoming_number>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_list_an_incoming_number (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
__________________________________________________________________________ ClusterTest.test_list_available_numbers __________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_list_available_numbers>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86.../bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_list_available_numbers (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
__________________________________________________________________________ ClusterTest.test_list_incoming_numbers ___________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_list_incoming_numbers>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...r/bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_list_incoming_numbers (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
____________________________________________________________________________ ClusterTest.test_send_text_message _____________________________________________________________________________

self = <test_cluster.ClusterTest testMethod=test_send_text_message>

    def setUp(self):
>       self.from_number = os.environ["TWILIO_FROM_NUMBER"]

tests/cluster/test_cluster.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = environ({'PDM_BUILD_SCM_VERSION': '8.11.1', 'PATH': '/home/tkloczko/rpmbuild/BUILDROOT/python-twilio-8.11.1-2.fc35.x86...'/usr/bin/pytest', 'PYTEST_CURRENT_TEST': 'tests/cluster/test_cluster.py::ClusterTest::test_send_text_message (call)'})
key = 'TWILIO_FROM_NUMBER'

    def __getitem__(self, key):
        try:
            value = self._data[self.encodekey(key)]
        except KeyError:
            # raise KeyError with the original key value
>           raise KeyError(key) from None
E           KeyError: 'TWILIO_FROM_NUMBER'

/usr/lib64/python3.8/os.py:675: KeyError
===================================================================================== warnings summary ======================================================================================
tests/unit/base/test_version.py:7
  /home/tkloczko/rpmbuild/BUILD/twilio-python-8.11.1/tests/unit/base/test_version.py:7: PytestCollectionWarning: cannot collect test class 'TestPage' because it has a __init__ constructor (from: tests/unit/base/test_version.py)
    class TestPage(Page):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
FAILED tests/cluster/test_cluster.py::ClusterTest::test_allow_special_characters_for_friendly_and_identity_name - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_calling_twiml_object - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_calling_twiml_string - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_list_an_incoming_number - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_list_available_numbers - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_list_incoming_numbers - KeyError: 'TWILIO_FROM_NUMBER'
FAILED tests/cluster/test_cluster.py::ClusterTest::test_send_text_message - KeyError: 'TWILIO_FROM_NUMBER'
========================================================================= 7 failed, 530 passed, 1 warning in 5.00s ==========================================================================

@kloczek
Copy link
Author

kloczek commented Mar 21, 2024

Looks like filtering all code over pyupgrade solved all issues with failing units.
Issue still remains with errors which I've initially reported.

@kloczek
Copy link
Author

kloczek commented Mar 21, 2024

I've added #781

@tiwarishubham635
Copy link
Contributor

I think #783 addresses the same issue. Right?

@tiwarishubham635 tiwarishubham635 added the status: waiting for feedback waiting for feedback from the submitter label Apr 4, 2024
@kloczek
Copy link
Author

kloczek commented Apr 5, 2024

I think #783 addresses the same issue. Right?

Yep 😋

@tiwarishubham635
Copy link
Contributor

I have added a comment, please check

@tiwarishubham635 tiwarishubham635 linked a pull request Apr 22, 2024 that will close this issue
8 tasks
@tiwarishubham635 tiwarishubham635 added type: twilio enhancement feature request on Twilio's roadmap and removed status: waiting for feedback waiting for feedback from the submitter labels Apr 22, 2024
@tiwarishubham635
Copy link
Contributor

Created an internal ticket to be prioritized. +1s will help it move up the queue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: twilio enhancement feature request on Twilio's roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants