'Pytest hangs indefinitely running tests after Selenium image update

A day ago selenium updated their standalone-images (https://hub.docker.com/search?q=selenium&type=image) and at the same time selenium 4.0.0 was released on pypi (https://pypi.org/project/selenium/#history)

I am using pytest and selenium to test my frontend of my django app and everything was working perfectly fine until yesterday when the release came out. What happens now is that when I run pytest (in PyCharm) the test just runs indefinitely without throwing an error or anything. It just never stops running.

I very sure that the release is the problem, because when I pull the chrome-debug image, which was updated 15 days ago (in comparison to the chrome-standalone yesterday), my test-suite runs just fine again.

I also tried pulling the standalone-firefox image to check if it may be a problem with only the standalone-chrome image, but I get the same result.

Now, an intermediate solution is of course to use the chrome-debug image, but I am afraid that they will update this one soon too which will break my test-suite yet again, plus the standalone images are more lightweight.

I have absolutely no clue what's going on.

A minimal example of my test suite:

Docker-compose:

  selenium:
    image: selenium/standalone-chrome
    ports:
      - 4444:4444
      - 5900:5900

Docker-file;

FROM python:3.9-alpine3.14
....
....

Test-config:

def pytest_configure(config):
    """Adjust socket configuration for live_server fixture."""

    config.option.liveserver = socket.gethostbyname(socket.gethostname())

Test:


@pytest.fixture()
def browser():
    browser = webdriver.Remote(
        command_executor="http://selenium:4444/wd/hub",
        desired_capabilities=DesiredCapabilities.CHROME,
    )
    browser.implicitly_wait(5)
    yield browser
    browser.close()



def test_visit_page(browser, live_server):
    result = browser.get(live_server.url)
    assert "This text is in my page source" in result.page_source

I was hoping (no bad intentions ;)) anyone else ran into the same problem and maybe found a way to fix it? There is no issue open for this on seleniums github though. Or maybe someone can land me a hand? Apologies I cannot post any errors or stacktraces, I'd really like one myself. Any help is appreciated, thanks!

Ah and if I do not run this from PyCharm, but from a normal terminal I get:

Test session starts (platform: linux, Python 3.9.7, pytest 6.2.5, pytest-sugar 0.9.4) django: settings: config.settings.test (from ini) Matplotlib: 3.4.3 Freetype: 2.6.1 rootdir: /app, configfile: pytest.ini plugins: django-4.4.0, Faker-9.3.1, cov-3.0.0, mpl-0.13, sugar-0.9.4 collecting ...

And it hangs... Maybe it is downloading those huge packages= But it should already be installed in the docker environment....



Solution 1:[1]

If the version of python you have used while developing is greater than 3.6, it will hang.

For workaround, you can use --trace flag with pytest command. But this is not the valid solution.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yunnosch