- Java锁的逻辑(结合对象头和ObjectMonitor)
- 还在用饼状图?来瞧瞧这些炫酷的百分比可视化新图形(附代码实现)⛵
- 自动注册实体类到EntityFrameworkCore上下文,并适配ABP及ABPVNext
- 基于Sklearn机器学习代码实战
本文撰写于 2023.7.10 。
项目结构如下 。
D:\Gitee\DemoRepo (17.97MB)
+-- testCases (1.03KB)
| +-- conftest.py (252b)
| +-- pmCases (574b)
| | +-- conftest.py (259b)
| | `-- test_logout.py (315b)
顶层conftest.py内容 。
import pytest
@pytest.fixture(scope='session')
def fix_all():
print('fix_all')
pmCases下的conftest.py内容 。
import pytest
@pytest.fixture(scope='session', autouse=True)
def fix_all2():
print('fix_all2')
test_logout.py内容 。
import pytest
def test_logout(fix_all):
print('test_logout')
if __name__ == '__main__':
pytest.main(['-sv',__file__])
用的Pytest7.3.1,而实际7.4.0之前也就只有一个7.3.2了 。
你是可以执行test_logout.py的 。
效果如下 。
test_logout.py::test_logout fix_all2
fix_all
test_logout
PASSED
所以按照以前的认识 。
注意把pytest更新到pytest7.4.0 。
同样执行test_logout.py 。
效果如下 。
D:\Gitee\DemoRepo\venv\Scripts\python.exe D:/Gitee/DemoRepo/testCases/pmCases/test_logout.py
============================= test session starts =============================
platform win32 -- Python 3.9.6, pytest-7.4.0, pluggy-1.2.0 -- D:\Gitee\DemoRepo\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\Gitee\DemoRepo\testCases\pmCases
collecting ... collected 1 item
test_logout.py::test_logout fix_all2
ERROR
=================================== ERRORS ====================================
________________________ ERROR at setup of test_logout ________________________
file D:\Gitee\DemoRepo\testCases\pmCases\test_logout.py, line 10
def test_logout(fix_all):
E fixture 'fix_all' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, fix_all2, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
D:\Gitee\DemoRepo\testCases\pmCases\test_logout.py:10
=========================== short test summary info ===========================
ERROR test_logout.py::test_logout
============================== 1 error in 0.01s ===============================
进程已结束,退出代码为 0
很清楚的提示 。
E fixture 'fix_all' not found
子目录无法去引用上级目录的fixture 。
而同级目录不受影响 。
我们的实战课就会用到子目录下的测试文件调用上级目录的fixture,是没问题的,但现在会受影响.
这是为何呢?第一个想法就是版本变动了。但觉得不太可以理解,正常版本变动对这些逻辑不应该去大改,除非是大版本的改变。因为一旦出现这样的引用,你以前的项目会无法调用.
很多的时候你是在终端下执行 。
修改test_logout.py 。
def test_logout(fix_all):
print('test_logout')
终端下执行 。
D:\Gitee\DemoRepo\testCases>pytest
# 这是成功的
这样执行 。
D:\Gitee\DemoRepo\testCases\pmCases>pytest
# 报错跟上面一样 E fixture 'fix_all' not found
基于此,如果你是终端下执行的话,其实是没啥影响的.
只有你要在子目录下测试或者单独执行子测试用例时可能会有问题 。
https://docs.pytest.org/en/7.4.x/changelog.html# 。
发布时间 (2023-06-23) 。
ExceptionInfo.from_exception()
, a simpler way to create an ExceptionInfo
from an exception. This can replace ExceptionInfo.from_exc_info()
for most uses. #10872 : Update test log report annotation to named tuple and fixed inconsistency in docs for pytest_report_teststatus hook. 。
#10907 : When an exception traceback to be displayed is completely filtered out (by mechanisms such as __tracebackhide__ , internal frames, and similar), now only the exception string and the following message are shown
“All traceback entries are hidden. Pass --full-trace to see hidden and internal frames.”. 。
Previously, the last frame of the traceback was shown, even though it was hidden. 。
#10940 : Improved verbose output ( -vv ) of skip and xfail reasons by performing text wrapping while leaving a clear margin for progress output. 。
Added TerminalReporter.wrap_write() as a helper for that. 。
#10991 : Added handling of %f directive to print microseconds in log format options, such as log-date-format . 。
#11005 : Added the underlying exception to the cache provider’s path creation and write warning messages. 。
#11013 : Added warning when testpaths is set, but paths are not found by glob. In this case, pytest will fall back to searching from the current directory. 。
#11043 : When --confcutdir is not specified, and there is no config file present, the conftest cutoff directory ( --confcutdir ) is now set to the rootdir . Previously in such cases, conftest.py files would be probed all the way to the root directory of the filesystem. If you are badly affected by this change, consider adding an empty config file to your desired cutoff directory, or explicitly set --confcutdir . 。
#11081 : The norecursedirs check is now performed in a pytest_ignore_collect implementation, so plugins can affect it. 。
If after updating to this version you see that your norecursedirs setting is not being respected, it means that a conftest or a plugin you use has a bad pytest_ignore_collect implementation. Most likely, your hook returns False for paths it does not want to ignore, which ends the processing and doesn’t allow other plugins, including pytest itself, to ignore the path. The fix is to return None instead of False for paths your hook doesn’t want to ignore. 。
#8711 : caplog.set_level() and caplog.at_level() will temporarily enable the requested level if level was disabled globally via logging.disable(LEVEL) . 。
--tb=line
mode where pytest.fail(pytrace=False)
tests report None
. --last-failed
whole-file skipping functionality (“skipped N files”) for non-python test files . testpaths
to be considered for loading initial conftests, even when it was not utilized (e.g. when explicit paths were given on the command line). Now the testpaths
are only considered when they are in use. __tracebackhide__ = True
still being shown for chained exceptions (parts after “… the above exception …” message). --debug
. caplog.set_level()
. -c
to now include --config-file
to make it clear that this flag applies to the usage of a custom config file. 原文 。
When `--confcutdir` is not specified, and there is no config file present, the conftest cutoff directory (`--confcutdir`) is now set to the [rootdir](https://docs.pytest.org/en/7.4.x/reference/customize.html#rootdir). Previously in such cases, `conftest.py` files would be probed all the way to the root directory of the filesystem. If you are badly affected by this change, consider adding an empty config file to your desired cutoff directory, or explicitly set `--confcutdir`.
译文 。
当未指定--confcutdir并且没有配置文件存在时,conftest截断目录(--confcutdir)现在被设置为rootdir。在以前的情况下,conftest.py文件会一直被探测到文件系统的根目录。如果你受到这个变化的严重影响,考虑在所需的截断目录中添加一个空的配置文件,或者明确地设置--confcutdir。
指定参数--confcutdir 。
示例1: test_logout.py执行 。
import pytest
def test_logout(fix_all):
print('test_logout')
if __name__ == '__main__':
pytest.main(['-sv','--confcutdir=..',__file__]) # 意思是设定conftest.py的搜索根目录是当前目录上级
示例2: 终端执行 。
# 你在pmCases下执行
# 如果在项目根目录下,本来就是ok的
pytest --confcutdir=..
示例3: pytest.ini 。
[pytest]
# 改为实际的项目根目录即可
addopts = --confcutdir="D:\Gitee\DemoRepo"
--confcutdir=.
(因为你是把pytest.ini放在根目录下的) 截止到撰写本文的时候(2023-7-10)发现 。
pip install pytest会安装最新的Pytest7.4.0 。
而通过pycharm安装则是Pytest7.3.1 。
对于这个参数,命令行--help的解释是 。
--confcutdir=dir Only load conftest.py's relative to specified dir
最后此篇关于pytest7.4版本的一个变更,可能会影响你的项目的文章就讲到这里了,如果你想了解更多关于pytest7.4版本的一个变更,可能会影响你的项目的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这是一个非常笼统的问题,我希望我能答对。 我正在研究 SSL/TLS 重新协商并已阅读了一些内容。这是我从阅读中了解到的内容: 从 SSL/TLS 重新协商的角度来看,客户端分为两个主要组,打补丁的和
第一个屏幕是艺术的细节。当我向上滚动时,标题将是 alpha。我点击另一个“艺术”到另一个细节 UI,然后按回到 Previous UI。之前的UI标题是黑色的,怎么变透明了。 布局:
想知道 mv 对基表的影响。它会减慢基表的速度吗?它什么时候开始写入 mv,就像同时写入基表和 mv 一样? 如果我有 local_quorum 的 CL 且 RF=3,客户端是否必须等到写入 mv
似乎在任何地方都找不到太多关于此问题的帮助,所以我想我会在这里尝试。 我正在尝试制作一个简单的 for 循环,当我将鼠标悬停在 html 卡上时,它会隐藏卡中的一些文本。该卡有一个简单的名字和姓氏,我
我有一个程序每帧运行 tick() 方法。我希望一个对象根据设定的重力常数下落,因此我创建了一个 Ball 对象,该对象会将其位置更新为前一帧的位置减去 y 速度。每个刻度 y 速度都会减少重力常数。
我的 KeyHandler 在这里: private void KeyHandler(java.awt.event.KeyEvent evt) {
我有一个方法,其中使用了很多其他类,包括链接列表、队列和堆栈。在我的方法中,我有一个 for 循环,我想在其中弹出堆栈(方便地命名为 s)并将队列(方便地命名为 q)出队到 s1 和 q1。由于某种原
我有一个 JTree 节点数组和另一个自定义对象的相应数组。 我想要什么:当选择 JTree 的节点时,相应对象(其数组中索引与节点数组中所选节点索引相同的对象)的字段填充 JLabels。 我被困在
我知道浏览器完成了处理客户端脚本(Javascript、JQuery 等)的所有工作,但想知道在性能方面是否还有其他重要因素(网络速度、客户端计算机速度、服务器环境) 如果它完全依赖于浏览器(类型和版
我有一个 Android 服务在后台运行,它将使用以下代码: while(true) { ServerSocket server = new ServerSocket(1234); Socke
对JQM有以下疑惑: 1.如果我们在单独的 html 文件中使用重复的 id,对 jquery mobile 有什么影响。 假设我们在单独的 html 文件中有重复的 id,但如果我们不使用该 id
我正在尝试更新两个(inventory、sold)MySQL 表的表库存。 假设我们正在处理的 sku 是 BT888-16 UPDATE inventory JOIN sold ON invento
我使用这种方法来更改我的表格单元格值, 它在 jtable 上改变但在文本文件上没有改变! public class user_AllBooks extends AbstractTableModel
我想在向表中插入数据时创建一个 MYSQL 存储过程,数据也会被插入到其他服务器表中。 我知道这在 ORACLE 数据库中是可能的,但我不知道它是否适用于 MYSQL。 有什么办法吗? 最佳答案 是的
我在 css 方面非常糟糕,只能靠 SO 答案来解决 - 但是我找不到针对这个特定问题的任何解释。 我有一个表单,其中包含一个 textarea 和一个 button(input/submit),仅此
我在一个元素上有动画,但它的移动也会影响 sibling 。如何在不影响兄弟元素的情况下仅在元素上使用动画? 问题示例: function animateSearch() { $('.glyph
我试图在我的 ViewController 中的 UIView 的所有四个边上建立一个阴影 — 在我通过 Xcode 向 UIView 添加约束之前,它工作得很好。我怎样才能使 UIView 的阴影显
自从我使用 JavaScript 以来已经有一段时间了 - 在获得证书之后我开始学习 Perl 并从那时起就一直使用它。我只是想重新开始使用 JS,我已经写了这个,我想说的是,这是一个简单的小脚本,可
我正在处理一个 HTML 元素,我添加了一个复选框,选中后会高亮显示所有文本输入字段。唯一的问题是一些输入字段在表格内,出于某种原因我无法用我的代码影响它们。任何帮助将不胜感激。 相关代码: HTML
我为 String 类创建了一个小扩展,以便方便地从中删除字符。这是它的样子: mutating func drop(characters chars: [String]) { for c i
我是一名优秀的程序员,十分优秀!