草庐IT

test_client

全部标签

python - 如何让 Travis CI 安装 tests_require 中声明的 Python 依赖项?

我有带有setup.py的Python包。它具有在install_requires中声明的常规依赖项和在tests_require中声明的开发依赖项,例如flake8.我认为pipinstall-e.或运行pythonsetup.pytest也会安装我的开发依赖项,它们将可用。然而,显然它们不是,我很难正确设置我的TravisCI构建。install:-"pipinstall-e."script:-"pythonsetup.pytest"-"flake8"如上配置的构建将失败,因为flake8将不会被发现为有效命令。我还尝试从pythonsetup.pytest命令内部调用flake8

python - 在子文件夹中使用 pytest where test

我正在使用pythonpytest来运行我的单元测试。我的项目文件夹是:Main-包含数据文件:A.txtMain\Tests-我运行pytest的文件夹Main\Tests\A_test-包含测试文件的文件夹A_test文件夹中的测试使用文件A.txt(位于Main文件夹中)。我的问题是,当我运行py.test时,测试失败,因为它找不到A.txt。我发现是因为pytest在运行测试时使用了路径Main\Test,而不是将路径改为Main\Tests\A_test(我是在测试文件中打开A.txt时使用相对路径)我的问题:有没有办法让pytest将目录更改为它为每个测试执行的测试文件夹?

python - 使用 if __name__ == '__main__' : for tests

当您编写一些自给自足的脚本时,使用if__name__=='__main__'作为编写测试的地方是不是一个坏主意? 最佳答案 这实际上取决于您的代码和脚本的目的。对于大型和复杂的项目,您肯定必须将所有测试放在一个单独的地方。但是在处理一些小的事情时,将测试与代码一起进行可能是一个很好的解决方案-这是doctest的主要思想(这是一个很棒的Python模块,允许您在文档字符串中编写测试)。在这种情况下,您的if__name__=='__main__'将如下所示:if__name__=="__main__":importdoctestd

python - 错误 "The object invoked has disconnected from its clients"- 使用 python 和 win32com 自动化 IE 8

我想自动化InternetExplorer8(在Windows7上使用python2.7)机器。这是我在apostfoundonSO之后的代码:importsys,timefromwin32com.clientimportWithEvents,DispatchimportpythoncomimportthreadingstopEvent=threading.Event()classEventSink(object):defOnNavigateComplete2(self,*args):print"complete",argsstopEvent.set()defwaitUntilRead

python - 简单的 Python UDP 服务器 : trouble receiving packets from clients other than localhost

所以,我尝试使用的非常简单的代码在这里:http://wiki.python.org/moin/UdpCommunication(也在这里):发送:importsocketUDP_IP="127.0.0.1"UDP_PORT=5005MESSAGE="Hello,World!"print"UDPtargetIP:",UDP_IPprint"UDPtargetport:",UDP_PORTprint"message:",MESSAGEsock=socket.socket(socket.AF_INET,#Internetsocket.SOCK_DGRAM)#UDPsock.sendto(M

将nacos从本地切换到远程服务器上时报错:客户端端未连接,Client not connected

报错信息:09:34:38.438[com.alibaba.nacos.client.Worker]ERRORcom.alibaba.nacos.common.remote.client-Sendrequestfail,request=ConfigBatchListenRequest{headers={charset=UTF-8,Client-AppName=unknown,Client-RequestToken=65c0fbf47282ae0a7b85178dcf076771,Client-RequestTS=1684114478337,exConfigInfo=true},requestI

python - python 的新 'pip wheel' 是否支持为 tests_requires 中列出的依赖项构建轮子?

我使用setuptools'tests_require'来指定测试我的包所需的依赖项。tests_require-http://pythonhosted.org/distribute/setuptools.html#new-and-changed-setup-keywords我已经开始使用wheelpackaginghttp://wheel.readthedocs.org/en/latest/并为我当前的包及其所有依赖项构建一个wheels目录。pipwheel--wheel-dir=/tmp/wheelhouse.不过,我还想为任何包tests_require中列出的所有包构建轮子。

python - 如何在没有详细测试进度的情况下显示详细的 py.test 差异?

py.test的--verbose选项需要显示断言失败的完整差异,但这也会在执行期间显示每个测试的全名(很吵)。我希望在断言失败时显示完整的差异,但我只希望在测试运行时显示单个.。有办法做到这一点吗? 最佳答案 不幸的是,似乎没有配置或命令行标志,因为它是硬编码的deepinsidepytest:当你定义--verbose时,你会得到整个包。但是,我设法想出了这个hackishhack。将以下函数放入您的conftest.py:defpytest_configure(config):terminal=config.pluginman

python - 如何在 Python 中使用 win32com.client 从 outlook 保存附件?

我尝试使用Python中的win32com模块阅读电子邮件并将附件下载到我自己的文件夹,我在获取附件对象时停止了:fromwin32com.clientimportDispatchimportdatetimeasdateoutlook=Dispatch("Outlook.Application").GetNamespace("MAPI")inbox=outlook.GetDefaultFolder("6")all_inbox=inbox.Itemsval_date=date.date.today()sub_today='Hi'att_today='Attachment.xlsx'for

python - 如何让 `python setup.py test -q` 更安静?

我刚刚开始一个Pyramid项目,遵循Pyramiddocs的建议.测试命令如下所示:../bin/pythonsetup.pytest-q..这给了我这个结果:$../bin/pythonsetup.pytest-qrunningtestrunningegg_infowritingrequirementstoclimas_ng.egg-info/requires.txtwritingclimas_ng.egg-info/PKG-INFOwritingtop-levelnamestoclimas_ng.egg-info/top_level.txtwritingdependency_li