我创建了一个pytest.ini文件,
addopts = --resultlog=log.txt
Run Code Online (Sandbox Code Playgroud)
这会创建一个日志文件,但我想在每次运行测试时创建一个新的日志文件。
我是 pytest 的新手,如果我在阅读文档时遗漏了任何内容,请原谅我。
谢谢
我正在使用Python 3.7,pip版本:10.0.1,操作系统:Windows 10
在CMD中,我使用以下命令安装依赖项:
Python -m pip install requirements.txt
Run Code Online (Sandbox Code Playgroud)
但它显示此消息:
找不到满足需求requirements.txt的版本(来自版本:)找不到符合要求的发行版
requirements.txt包含:
#Flask framework
Flask
#Flask packages
Flask-RESTful
Flask-JWT
Flask-SQLAlchemy
Flask-Mail
Run Code Online (Sandbox Code Playgroud) 我知道有用于性能测试和 py.test 分析的插件,但是有没有办法生成在测试后报告或以某种方式访问的任意值?
想象一下我有一个这样的测试
def test_minimum_learning_rate():
"""Make some fancy stuff and generate a learning performance value"""
learning_rate = fancy_learning_function().rate
pytest.report("rate", learning_rate)
assert learning_rate > 0.5
Run Code Online (Sandbox Code Playgroud)
这pytest.report(..)条线就是我想要的(但不存在,不是吗?)
现在我想要将minimum_learning_rate[rate]实际测试结果与报告一起写入(或者至少在屏幕上)。
Jenkins 的一些插件真的很好,它可以根据这些数据创建一个漂亮的图表。
这有典型的措辞吗?我一直在寻找kpi,arbitrary values但user defined values还没有任何运气..
tf.reset_default_graph()清除默认图形。退出tf.Session()上下文时如何清除图形?
示例(pytest):
import tensorflow as tf
def test_1():
x = tf.get_variable('x', initializer=1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(4 / 0)
print(sess.run(x))
def test_2():
x = tf.get_variable('x', initializer=1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(sess.run(x))
Run Code Online (Sandbox Code Playgroud) 我试图在主节点和工作节点之间共享数据库中的随机条目列表(我对共享资源的定义),并使用 pytest-xdist 并行化测试。我的代码遵循以下结构:
## in conftest.py
def get_db_entries():
connect to db
run a query with group by and random
returns one random entry per group as a list of dictionaries.
Run Code Online (Sandbox Code Playgroud)
我改编了https://hackebrot.github.io/pytest-tricks/shared_directory_xdist/提供的建议,以在主节点和工作节点之间共享数据库条目:
# in conftest.py
def pytest_configure(config):
if is_master(config):
# share db_entries across master and worker nodes.
config.db_samples = get_db_entries()
def pytest_configure_node(node):
"""xdist hook"""
node.slaveinput['db_entries'] = node.config.db_samples
def is_master(config):
"""True if the code running the given pytest.config object is running in a xdist master
node or not running xdist at …Run Code Online (Sandbox Code Playgroud) 我经常从我无法控制的库中得到很多弃用,我不想用它们污染测试执行。
我怎样才能避免这种情况而不冒从我自己的代码中禁用弃用的风险?
例子:
================================================================================ warnings summary ==================================================================================
.tox/py27-ansible25-unit/lib/python3.6/site-packages/toml/decoder.py:47
/Users/ssbarnea/os/molecule/.tox/py27-ansible25-unit/lib/python3.6/site-packages/toml/decoder.py:47: DeprecationWarning: invalid escape sequence \.
TIME_RE = re.compile("([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]{3,6}))?")
.tox/py27-ansible25-unit/lib/python3.6/site-packages/sh.py:424
/Users/ssbarnea/os/molecule/.tox/py27-ansible25-unit/lib/python3.6/site-packages/sh.py:424: DeprecationWarning: invalid escape sequence \d
rc_exc_regex = re.compile("(ErrorReturnCode|SignalException)_((\d+)|SIG[a-zA-Z]+)")
.tox/py27-ansible25-unit/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py:152
/Users/ssbarnea/os/molecule/.tox/py27-ansible25-unit/lib/python3.6/site-packages/botocore/vendored/requests/packages/urllib3/connectionpool.py:152: DeprecationWarning: invalid escape sequence \*
Run Code Online (Sandbox Code Playgroud) 我一整天都在安装 SpaCy。
sudo pip install -U spacy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting spacy
Using cached https://files.pythonhosted...
Installing build dependencies ... done
Complete output from command python setup.py egg_info:
Failed building wheel for blis
ERROR: Failed to build one or more wheels
Traceback (most recent call last):
File "/tmp/pip-build-env-e4fo917j/lib/python3.7/site-packages/setuptools/installer.py", line 128, in fetch_build_egg
subprocess.check_call(cmd)
File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpgp2s1vb0', '--quiet', 'blis<0.5.0,>=0.4.0']' returned non-zero exit status 1. …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用virtualenv在Sierra 10.12.6上使用Python 2.7.14在我的Macbook上安装Django 2.0,但我不断在底部获取此错误代码:
(抱歉提前,我是新来的,所以不确定如何让它更方便用户阅读,所以还附上了截图)
Joeys-MBP:somename joeybaloney$ pip install django
Collecting django
Using cached Django-2.0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/wj/jbbqxb5d6ld9q00gw73mjzp00000gn/T/pip-build-QicGdd/django/setup.py", line 32, in <module>
version = __import__('django').get_version()
File "django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "django/utils/version.py", line 61, in <module>
@functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/wj/jbbqxb5d6ld9q00gw73mjzp00000gn/T/pip-build-QicGdd/django/
Run Code Online (Sandbox Code Playgroud)
我已经在Stackoverflow上尝试了几乎所有解决方案,例如更新工具,使用sudo pip …
我正在尝试删除 pytest-html 报告中存在的环境表,但我不知道该怎么做?
我附上了 pytest-html 报告 在这里输入图像描述
例如我有这样的测试数据:
PARAMS = {'pic1': [1, 2, 3], 'pic2': [14, 15], 'pic3': [100, 200, 300]}
Run Code Online (Sandbox Code Playgroud)
我需要从中下载每个关键图片PARAMS并生成[1, 2, 3]将使用该图片的单独测试。之后,当每对测试'pic1': [1, 2, 3]结束时,删除图片,然后下载下一张,依此类推......粗略地说,生成的测试应该如下所示:
test_pic[pic1-1]
test_pic[pic1-2]
test_pic[pic1-3]
test_pic[pic2-14]
test_pic[pic2-15]
test_pic[pic3-100]
test_pic[pic3-200]
test_pic[pic3-300]
Run Code Online (Sandbox Code Playgroud)
但里面会有一个下载图像的逻辑。
我没有找到如何在 pytest 中做到这一点的方法。
请帮忙。
根据pytest测试运行的总体测试结果,我要执行条件拆卸。这意味着必须在执行完所有测试之后但离开测试运行程序之前,才能访问总体测试结果。我该如何实现?
python ×10
pytest ×8
python-3.x ×4
testing ×2
arm ×1
django ×1
kpi ×1
logging ×1
macos ×1
performance ×1
pip ×1
pytest-html ×1
python-2.7 ×1
raspberry-pi ×1
report ×1
spacy ×1
tensorflow ×1
unit-testing ×1
xdist ×1