草庐IT

test_slice

全部标签

python - Py.Test 与配置文件

标题可能含糊不清,所以我试着在这里解释一下这个场景。我想在多个设备上测试python模块Foo。我已经创建了一个test_Foo.py文件。现在所有这些带有Foo的设备都需要不同的设置。例如,设备A需要使用参数X构建和测试Foo,而设备B需要使用参数Y构建和测试Foo。其中参数例如是设备ID。是否可以(以及如何)控制我的test_Foo.py使用配置文件。我使用YAML文件作为其他模块argparse.ArgumentParser的配置,但我想知道我可以在Py.Test中使用相同的概念。 最佳答案 您是否可以控制将用于在每个环境中调

python - py.test : hide stacktrace lines from unittest module

py.test堆栈跟踪目前看起来像这样:Traceback(mostrecentcalllast):File"/home/foo_tbz_di476/src/djangotools/djangotools/tests/ReadonlyModelTestCommon.py",line788,intest_stale_or_missing_content_typesself.assertEqual([],errors,'Stale/MissingContentTypes:%s'%'\n'.join(errors))File"/usr/lib64/python2.7/unittest/cas

python - 使用 map : A value is trying to be set on a copy of a slice from a DataFrame 时的 Pandas 警告

我有以下代码并且可以正常工作。这基本上重命名了列中的值,以便以后可以合并它们。pop=pd.read_csv('population.csv')pop_recent=pop[pop['Year']==2014]mapping={'Korea,Rep.':'SouthKorea','Taiwan,China':'Taiwan'}f=lambdax:mapping.get(x,x)pop_recent['CountryName']=pop_recent['CountryName'].map(f)Warning:Avalueistryingtobesetonacopyofaslicefrom

python - 从命令行为 py.test 指定 fixture 参数

我想将命令行参数传递给py.test以创建fixture。例如,我想将数据库主机名传递给下面的fixture​​创建,因此它不会被硬编码:importpytestdefpytest_addoption(parser):parser.addoption("--hostname",action="store",default='127.0.0.1',help="specifyIPoftesthost")@pytest.fixture(scope='module')defdb(request):return'CONNECTEDTO['+request.config.getoption('--

python - ProgrammingError : (1146, "Table ' test_<DB>.<TABLE >' doesn' t exist") 为 Django 运行单元测试时

我正在使用Django框架运行单元测试并收到此错误。运行实际代码没有这个问题,运行单元测试会即时创建一个测试数据库,所以我怀疑问题出在那里。抛出错误的代码如下所示member=Member.objects.get(email=email_address)模型看起来像classMember(models.Model):member_id=models.IntegerField(primary_key=True)created_on=models.DateTimeField(editable=False,default=datetime.datetime.utcnow())flags=mo

python - nose2 与 py.test 隔离进程

我们一直在使用nosetest来运行和收集我们的单元测试(它们都是用我们喜欢的python单元测试编写的)。我们喜欢Nose的地方:使用标准的Python单元测试(我们喜欢这种强加的结构)。支持在xml中报告覆盖率和测试输出(对于jenkins)。我们缺少的是在隔离进程中运行测试同时保持良好错误报告的好方法(我们正在通过python测试C++库,因此段错误不应该是灾难性的)。鼻管似乎不再维护,我们遇到了一些问题。我们正在尝试弄清楚我们是否应该-修理/使用鼻管-切换到nose2并写入nosepipe2。-使用pytest或其他一些测试框架。我们更愿意使用具有良好社区的方法。看来我们的问题

python - 根据 py.test 中的参数跳过测试

我有一个带有session作用域的测试fixture,它是参数化的,例如@pytest.fixture(scope="session",params=["one","two","three"])defmyfixture():...在我的目录中,我有使用pytest.mark.usefixtures("myfixture")的文件和一个包含测试的文件应该只为myfixture运行"two"参数和py.test应该跳过它否则。有什么方法可以在py.test中实现这一点,或者我是否需要在myfixture()函数的某个类中设置一个特殊变量? 最佳答案

python - Pandas 数据帧 : SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

这个问题在这里已经有了答案:HowtodealwithSettingWithCopyWarninginPandas(20个答案)关闭3年前。我知道有很多关于此警告的帖子,但我找不到解决我的情况的方法。这是我的代码:df.loc[:,'my_col']=df.loc[:,'my_col'].astype(int)#df.loc[:,'my_col']=df.loc[:,'my_col'].astype(int).copy()#df.loc[:,'my_col']=df['my_col'].astype(int)它产生警告:SettingWithCopyWarning:Avalueistr

python - 错误 : Test failed: 400 (InvalidToken): The provided token is malformed or otherwise invalid

s3cmd通过运行从epel-testing仓库安装:yum--enablerepoepel-testinginstalls3cmd然后我用s3cmd--configure调用了配置工具,但我得到了这个错误:Testaccesswithsuppliedcredentials?[Y/n]Pleasewait,attemptingtolistallbuckets...ERROR:Testfailed:400(InvalidToken):Theprovidedtokenismalformedorotherwiseinvalid.Invokedas:/usr/bin/s3cmd--config

python - `py.test` 和 `__init__.py` 文件

我认为py.test在某种意义上是“独立的”,它“按原样”处理test_*.py文件,并且只导入这些文件中指定的模块文件,不考虑任何周围的文件。看来我错了。这是我与py.test的对话:$ls__init__.pytest_pytest.py$cat__init__.py$cattest_pytest.pydeftest_pytest():assertTrue$py.testtest_pytest.py=========================================================testsessionstarts===================