pycharm使用技巧

1.pycharm中python缩进快捷键:Shift+Tab 缩进,Tab 空格

2.pycharm中python加注释/取消注释快捷键:Ctrl+/

3.pycharm配置一下运行参数

  【Run】⇒ 【Edit Configurations】⇒ 【Additional Arguments】 ,添加参数:-m=webtest,在执行脚本,这个时候只会执行标记的用例

import pytest

@pytest.mark.webtest
def test_send_http():
    pass

def test_spmething_quick():
    pass

def test_another():
    pass

class TestClass:
    def test_method(self):
        pass

if __name__=="__main__":
    pytest.main(["-s","test_mark.py","-m=webtest"])

 

-m标记webtest执行的用例

 

 -m="not webtest"标记不执行的用例

4.

import pytest

@pytest.mark.webtest
def test_send_http():
    pass

def test_spmething_quick():
    pass

def test_another():
    pass

class TestClass:
    def test_method(self):
        pass
    def test_method2(self):
        pass

if __name__=="__main__":
    #pytest.main(["-s","test_mark.py","-m=webtest"])
    # pytest.main(["-s", "test_server.py", "-m=not webtest"])
    pytest.main(["-v","test_mark.py::TestClass::test_method test_mark.py::TestClass::test_method2"])

执行某个函数节点

 

 

-k=“http”执行相匹配的用例

 4.pytest.main("-s" ,"-v")

  -v显示运行的函数

  -s运行显示内部的打印信息

5.pycharm设置项目为pytest:File-》Settings-》……

 6. python的Script文件夹被替换掉了,Scripts文件夹为空,导致cmd下执行任何python命令都报错:不是内部或外部命令,也不是可运行的程序或批处理文件。

里面的执行文件都被替换掉了,重新卸载python安装一下

  

 7执行命令(pytest -s -q --alluredir Report)报错:

D:\Python\Smart_Interface_Test\Testact\Testact>pytest -s -q --alluredir Report
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\_pytest\main.py", line 199, in wrap_session
INTERNALERROR> config._do_configure()
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\_pytest\config\__init__.py", line 636, in _do_configure
INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\hooks.py", line 306, in call_historic
INTERNALERROR> res = self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\manager.py", line 67, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\manager.py", line 61, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\pluggy\callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "d:\program files (x86)\python\lib\site-packages\allure\pytest_plugin.py", line 80, in pytest_configure
INTERNALERROR> pytest.allure._allurelistener = testlistener
INTERNALERROR> AttributeError: module 'pytest' has no attribute 'allure'

 

怎么试都报错:可能安装的pytest版本和pytest-allure-adaptor不一致,卸载pytest :pip uninstall pytest;重新安装旧版本的pytest

安装成功之后,执行OK

 

7.AES加密报错:

卸载掉之前安装的包:下载下面的包

pip install pycryptodome  -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

 

posted @ 2019-01-04 17:44  大人的春天  阅读(408)  评论(0编辑  收藏  举报