繁体   English   中英

从终端运行测试的问题

[英]Issue with running test from terminal

我在PyCharm中使用Python 2.7.9

这是我的项目结构:

/JUAN
    /framework
        /config
        /page_objects
            /locators
        /tests
            /log_in
        /wrapper

locators文件夹中,我在JSON文件中存储了每个页面对象的定位器。 log_in文件夹中,我有一个测试。 这是测试的内容:

""" Test to verify the Sign In page."""

import unittest
from framework.page_objects.sign_in_page import SignInPage
from framework.tests.selenium_test_base import SeleniumTestBase

class TestVerifyPage(SeleniumTestBase):

    def test_verify_page(self):
        sign_inPage = SignInPage()
        sign_inPage.verify_elements_on_page()

    if __name__ == "__main__":
        unittest.main()

如果我运行它,右键单击并选择Run the test passes。 但是,如果我尝试通过终端执行它,我会遇到以下问题:

执行的行:

C:\JUAN\framework>python -m unittest ./tests/log_in/test_verify_page.py test_verify_page()

例外:

Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\lib\unittest\__main__.py", line 12, in <module>
    main(module=None)
  File "C:\Python27\lib\unittest\main.py", line 94, in __init__
    self.parseArgs(argv)
  File "C:\Python27\lib\unittest\main.py", line 149, in parseArgs
    self.createTests()
  File "C:\Python27\lib\unittest\main.py", line 158, in createTests
    self.module)
  File "C:\Python27\lib\unittest\loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "C:\Python27\lib\unittest\loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
ValueError: Empty module name

我找到2个解决方案:

解决方案1:

我所做的是删除了framework文件夹。

此外,终端中要执行的行是:

python -m unittest test_verify_page

解决方案2:

如果要保留模块结构,则需要在根目录中创建setup.py文件

setup.py内容:

from distutils.core import setup
setup(name='SxD',
      packages=['framework','config', 'page_objects','tests', 'wrapper'])

然后在root directoy中执行以下命令行:

python setup.py install

使用模块引用创建build文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM