I am trying to run selenium tests with pytest-django for my django app. Pytest-django provides a fixture called live_server. I am supposed to get the URL with live_server.url.

Now when I try to visit live_server.url it opens a browser but then the browser shows that the site cannot be reached. This is the not-working code I am trying to run:

class TestAdmin():

    def setup(self):     
        global browser
        browser = webdriver.Remote(

    def test_user_can_visit_website_with_chrome(self, live_server, setup):
        """Website is reachable in Chrome browser.


        assert 'mywebsite' in browser.title

The following code works if I use djangos inbuilt test runner:

class AdminTest(BaseTestCase):

    def test_login(self)
        path = urlparse(self.selenium.current_url).path
        self.assertEqual('/admin/', path)

So with django's inbuilt live_server_url it visits my localhost without complaining. But I need this in pytest and I don't really want to mix both syntaxes.

Reading the documentation it only says:

live_server This fixture runs a live Django server in a background thread. The server’s URL can be retrieved using the live_server.url attribute or by requesting it’s string value: unicode(live_server). You can also directly concatenate a string to form a URL: live_server + '/foo.

As I understand this it should work with the code that I try. I don't really see what I am missing.

Any help is greatly appreciated! Thanks very much in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.