这是我第一次尝试使用Iceweasel浏览器在树莓派上运行Selenium.我今晚尝试了一个简单的测试
# selenium test for /mod2
# verify: posts, and page name
class TestMod2Selenium(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_validate_page_elements(self):
driver = self.driver
driver.get("127.0.0.1:5000/mod2")
self.assertIn("Home - microblog", driver.title)
def tearDown(self):
self.driver.close()
Run Code Online (Sandbox Code Playgroud)
我在运行时得到的错误是:
=====================================================================
ERROR: test_validate_page_elements (__main__.TestMod2Selenium)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 58, in setUp
self.driver = webdriver.Firefox()
File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
self._wait_until_connectable()
File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable …
Run Code Online (Sandbox Code Playgroud) 烧瓶问题:我的run.py
文件在以下目录中
/Users/`<username>`/Python_stuff/flask
Run Code Online (Sandbox Code Playgroud)
但当我跑它时,它说
(api_automation)MacBook-Pro:flask `<username>`$ ./run.py
-bash: ./run.py: flask/bin/python: bad interpreter: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我很困惑为什么在过去的其他virtualenv上工作时会发生这种情况
这是run.py的样子:
#!flask/bin/python
from app import app
app.run(debug = True)
Run Code Online (Sandbox Code Playgroud) 我试图解决如何使用pytest从测试文件中获取测试名称的列表我已经做到这一点:
$ pytest --collect-only my_test_file.py
============================================================================================= test session starts ==============================================================================================
platform darwin -- Python 3.6.4, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /Users/.../automation, inifile:
plugins: xdist-1.20.1, metadata-1.7.0, html-1.17.0, forked-0.2, cloud-2.0.0
collected 6 items
<Module 'my_test_file.py'>
<UnitTestCase 'TestFile'>
<TestCaseFunction 'test_general'>
<TestCaseFunction 'test_search_0'>
<TestCaseFunction 'test_search_1'>
<TestCaseFunction 'test_search_2'>
<TestCaseFunction 'test_search_3'>
<TestCaseFunction 'test_search_4'>
Run Code Online (Sandbox Code Playgroud)
虽然这是一个良好的开端,但它是太多的信息.我应该通过什么来获取测试名称本身的列表?
有没有办法将 pytest 指向不同的 pytest.ini 文件?
我正在处理的应用程序有一个 pytest.ini 文件,用于在启动时运行单元测试,我不想修改该文件。
但是,在通过 pytest.main() 运行我的自动化测试时,我确实想将 pytest 指向不同的文件
pytest.main(['-p', 'no:django', '-v', '--json-report', '-m', test_marker])
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉 pytest 使用另一个位置的 pytest.ini 文件?