我对python很陌生,我正在努力学习有关单元测试的知识。我正在使用pytest对我的代码运行一些单元测试。与此示例非常相似的内容:
def test_calc_total():
total = mathlib.calc_total(4,5)
assert total == 9
我可能在这里不正确,但我正在学习,为了使您的函数是可测试的,它必须返回一个值。所有单元测试都是这样吗?
我发现我的大部分函数都无法进行测试,因为它们没有返回值。我正在创建一个票证跟踪系统,并将票证信息存储在一个数据文件中。下面是TicketDF类的一部分:
class TicketDF():
c
我想用Mockito模拟ConfigParser类来执行一个简单的测试:
from configparser import ConfigParser
from unittest import TestCase
from mockito import when, mock, verify
section = "SETTINGS"
# Here is an example function to test
def get_config():
ini_file = "settings.ini"
parser = ConfigParser()
下面是供您参考的终端日志
Traceback (most recent call last):
File "src/Utilities_test/test_cases_csv.py", line 39, in <module>
report_status = email_reporter(html_report_dir.split('/', 1)[-1])
File "src/Utilities_support/report_email.py", line 27, in email_reporter for item
我试着研究神经网络和深度学习().使用MichalDanielDobrzanski ()为Python3更新的版本。尝试在我的命令控制台中运行它,它在下面给出了一个错误。我尝试过卸载和重新安装setuptools、theano和numpy,但到目前为止还没有一个能工作。任何帮助都是非常感谢的!
以下是完整的错误日志:
WARNING (theano.configdefaults): g++ not available, if using conda: `conda install m2w64-toolchain`
C:\Users\ASUS\AppData\Local\Programs\Pyt
我尝试像这样解析文件:
[account]
User = first
[account]
User = second
我在Python中使用ConfigParser,但当我读取文件时:
Config = configparser.ConfigParser()
Config.read(file)
print (Config.sections())
我有错误:
While reading from ... : section 'account' already exists
如何解析此文件?有没有其他的库?(适用于python3)
也许这是一个愚蠢的问题,但是为什么这段代码不能在python2.7中工作呢?
from ConfigParser import ConfigParser
class MyParser(ConfigParser):
def __init__(self, cpath):
super(MyParser, self).__init__()
self.configpath = cpath
self.read(self.configpath)
它在以下方面失败:
TypeError: must be type, not classobj
在supe
我需要Openshift上的连接器吗。我尝试使用pip install mysql-python来安装它,但是它并没有被安装,并且我得到了以下问题:
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
但是,我不能安装这个包ConfigParser。以下是问题所在:
from configparser import ConfigParser
File "./configparser.py", line 397
_KEYCRE
我在服务器上安装了python-mysql.连接器和python3-mysql.连接器。并将python3.5设置为我的默认python。现在,我希望删除python-mysql.连接器,但得到以下错误:
ImportError: No module named 'ConfigParser'
我搜索了它,发现在python3 ConfigParser中更改为configparser,我认为这就是阻止删除包的原因。我使用这来移除python3-mysql连接器,这是可以的,但我不知道如何删除pyhton连接器。
任何想法都会对我有帮助。谢谢你的进阶。