pytest-plugins icon indicating copy to clipboard operation
pytest-plugins copied to clipboard

pytest-pyramid-server hostname error

Open phrfpeixoto opened this issue 5 years ago • 1 comments

I just installed this package to test a pyramid project, and I'm getting the following error:

def test_pyramid_server(pyramid_server):
    assert pyramid_server.dead is False
    assert pyramid_server.uri.startswith('http')

    assert pyramid_server.working_config.endswith('testing.ini')

Output goes:

======================================== ERRORS =========================================
_________________________ ERROR at setup of test_pyramid_server _________________________

request = <SubRequest 'pyramid_server' for <Function test_pyramid_server>>

    @yield_fixture(scope='session')
    def pyramid_server(request):
        """ Session-scoped Pyramid server run in a subprocess, out of a temp dir.
            This is a 'real' server that you can point a Selenium webdriver at.

            This fixture searches for its configuration in the current working directory
            called 'testing.ini'. All .ini files in the cwd will be copied to the tempdir
            so that config chaining still works.

            The fixture implementation in `PyramidTestServer` has more flexible configuration
            options, use it directly to define more fine-grained fixtures.

            Methods
            -------
            get_config() : Return current configuration as a dict.
            get()        : Query url relative to the server root.
            ..             Retry failures by default.
            post()       : Post payload to url relative to the server root.
            ..             Retry failures by default.

            Attributes
            ----------
            working_config  (`path.path`): Path to the config file used by the server at runtime
            .. also inherits all attributes from the `workspace` fixture
        """
>       with PyramidTestServer() as server:

.env/lib/python3.6/site-packages/pytest_pyramid_server.py:55:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <pytest_pyramid_server.PyramidTestServer object at 0x1082d9400>, config_dir = None
config_filename = None, extra_config_vars = None, kwargs = {}

    def __init__(self, config_dir=None, config_filename=None, extra_config_vars=None, **kwargs):
        """ Test server for a Pyramid project

        Parameters
        ----------
        config_dir:
            Path to a directory to find the config file/s. Defaults to current working dir, and
            all .ini files in the directory will be made available for config file chaining.
        config_filename:
            Name of the main config file to use. Defaults to testing.ini.
        extra_config_vars:
            Dict of any extra entries to add to the file, as { section: { key: value } }
        """
        self.extra_config_vars = extra_config_vars if extra_config_vars is not None else {}
        self.config_dir = config_dir if config_dir is not None else os.getcwd()
        self.config_filename = config_filename if config_filename else 'testing.ini'

        self.working_config = None
        self.original_config = Path(self.config_dir) / self.config_filename

        # Always print debug output for this process
        os.environ['DEBUG'] = '1'

        # Discover externally accessable hostname so selenium can get to it
>       kwargs['hostname'] = kwargs.get('hostname', socket.gethostbyname(os.uname()[1]))
E       socket.gaierror: [Errno 8] nodename nor servname provided, or not known

.env/lib/python3.6/site-packages/pytest_pyramid_server.py:87: gaierror
=================================== warnings summary ====================================
.env/lib/python3.6/site-packages/venusian/__init__.py:1
  /Users/ppeixoto/Projects/wellwatcher_api/.env/lib/python3.6/site-packages/venusian/__init__.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=============== 15 passed, 3 skipped, 1 warnings, 1 error in 4.49 seconds ===============

It seems the issue is related to a hostname not being passed as a parameter to the PyramidTestServer object, and also failing to be obtained by name resolution.

Related to #127

Now I'm not sure something is missing on my system, but it's clearly usable, as I'm working on it. It also does not seem very straightforward that a python lib should require a hostname being set on the machine.

phrfpeixoto avatar Aug 09 '19 19:08 phrfpeixoto

I believe this was fixed in v1.7.0 - when socket.gethostname() fails to resolve it now defaults to localhost. Could you confirm, and then I'll close this issue, thanks.

eeaston avatar Nov 19 '21 16:11 eeaston