Background Image
Table of Contents Table of Contents
Previous Page  438 / 478 Next Page
Information
Show Menu
Previous Page 438 / 478 Next Page
Page Background

1. You

could

run theDjango dev server froma console instead, but the problem is that PythonAnywhere consoles

don’t always run on the same server, so there’s no guarantee that the console you’re running your tests in is

the same as the one you’re running the server in. Plus, when it’s running in the console, there’s no easy way

of visually inspecting how the site looks.

self._get_firefox_output())

selenium.common.exceptions.WebDriverException: Message: 'The browser appears to

have exited before we could connect. The output was: Error: no display

specified\n'

The fix is to use

Xvfb

, which stands for X Virtual Framebuffer. It will start up a “virtual”

display, which Firefox can use even though the server doesn’t have a real one.

If, instead, you see "

ImportError, no module named selenium

“, do

a

pip3 install --user selenium

.

The command

xvfb-run

will run the next command in Xvfb. Using that will give us our

expected failure:

$

xvfb-run python3 functional_tests.py

Traceback (most recent call last):

File "tests.py", line 11, in <module>

assert 'Django' in browser.title

AssertionError

Setting Up Django as a PythonAnywhere Web App

Shortly after that, we set up Django. Rather than using the

django-admin.py start

project

command, I recommend you use the PythonAnywhere quick-start option in

the Web tab. Add a new web app, choose Django, Python 3, and then use

superlists

as

the project name.

Then, instead of running the test server from a console on

localhost:8000

, you can

use the real URL of your PythonAnywhere web app:

browser

.

get

(

'http://my-username.pythonanywhere.com'

)

You’ll need to remember to hit “ReloadWeb App” whenever youmake

changes to the code, to update the site.

That should work better.

1

410

|

Appendix A: PythonAnywhere