在Obey The Testing Goat上阅读教程,我在使用环境变量时遇到错误。使用Django 1.11,Selenium 3和Python 3.6。
(py36) C:\testgoat\superlists>STAGING_SERVER=superlists-staging.ottg.eu python manage.py test functional_tests
'STAGING_SERVER' is not recognized as an internal or external command,
operable program or batch file.
如果我正确理解了教程,则使用环境变量STAGING_SERVER
,使用真实服务器而不是Django的测试服务器运行测试。
django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import WebDriverException
import time
import unittest
import sys
import os
MAX_WAIT = 10
class NewVisitorTest(StaticLiveServerTestCase):
def setUp(self):
self.browser = webdriver.Firefox()
staging_server = os.environ.get('STAGING_SERVER')
if staging_server:
setattr(self, 'live_server_url', 'http://' + staging_server)
[...]