pytest

docker学习7-Dockerfile制作自己的镜像文件

霸气de小男生 提交于 2019-11-28 13:50:25
前言 如果你是一个python自动化测试人员,某天你在公司终于完成了一个项目的接口自动化脚本工作,在你自己常用的本机或者服务器上调试完成了脚本,稳稳地没问题。 可是晚上下班回家,你自己找了个linux的服务器,想在家里也练练手,于是重新安装python3.6版本,网上找个教程巴拉巴拉的一大堆指令安装。 第二天你回到公司,领导说你这个脚本能不能放到另外一套环境的服务器上执行(与你本机环境是不通的),于是你又重复安装一遍python3.6环境和执行脚本的一些依赖包。 运气好还能联网pip在线安装,运气不好,都不能连接外网,只能本地安装。于是乎你开始怀疑人生,为什么我要重复安装这么多次环境啊。。。。 要是100个不同服务器,我是不是得安装100次啊,于是乎你会想:我是不是可以做一个虚拟的python3.6环境,事先安装好我需要的依赖包。 把做好的虚拟环境传到某个仓库(类似github),哪个机器需要用到,就一键导入过去就ok了,于是docker制作自己的镜像文件势在必行了,这就是今天要说的Dockerfile制作一个属于自己的镜像文件。 Dockerfile简介 Dockerfile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本。 简单来说,Dockerfile就是把我们安装环境的每个步骤和指令,放到一个文件,最后一键执行,最后做成一个你想要的环境。

pytest cannot find module [duplicate]

流过昼夜 提交于 2019-11-28 12:44:54
This question already has an answer here: Ensuring py.test includes the application directory in sys.path 3 answers I am following the pytest good practices or at least I think I am . However, pytest cannot find my module. It seems not to include the current directory in its PYTHONPATH . The source file: def add(x, y): return x + y The test file: import pytest from junk.ook import add def test_add_true(): assert add(1, 1) == 2 And the shell output with a Python 3 virtual environment called "p3". p3; pwd /home/usr/tmp/junk p3; ls total 0 0 junk/ 0 tests/ p3; ls junk total 4.0K 4.0K ook.py 0 _

Avoid printing of dots

谁说我不能喝 提交于 2019-11-28 10:21:41
问题 I run pytest with option -q . Unfortunately this prints out a lot of dots. Example: ...................................................................................s...............s...................................ssssss..................................................................................................................................s..............s.........................s....................................................................................................

Usual pytest workflow - can't run tests in a file

守給你的承諾、 提交于 2019-11-28 10:20:19
问题 I'm trying to setup a project (Python 3.4.4, pytest 3.3.1) to use pytest, but pytest is failing to run tests in a file or a directory. I think I'm using pytest wrong, but am not what the correct workflow would be. What I've tried Following the suggestions in "Good Integration Practices" and also due to the personal preference of having the source and the tests in separate folders, I have setup my project as follows: parent_directory/ setup.py src/ project_name/ __init__.py # empty utils.py

How to skip a pytest using an external fixture?

[亡魂溺海] 提交于 2019-11-28 09:45:43
Background I am running a py.test with a fixture in a conftest file . You can see the code below(this all works fine): example_test.py import pytest @pytest.fixture def platform(): return "ios" @pytest.mark.skipif("platform == 'ios'") def test_ios(platform): if platform != 'ios': raise Exception('not ios') def test_android_external(platform_external): if platform_external != 'android': raise Exception('not android') conftest.py import pytest @pytest.fixture def platform_external(): return "android" Problem Now I want to be able to skip some tests that do not apply to my current test-run. In my

Run py.test test in different process

 ̄綄美尐妖づ 提交于 2019-11-28 08:43:29
问题 I'm trying to test tensorflow program. I'm setting up tensorflow session using parametrized py.test fixture: @pytest.fixture(scope="session", params=configuration) def session(request): if request.param == 'tensorflow': return tf.Session() elif request.param == 'tensorflow-eager': tfe.enable_eager_execution() return tf.Session() elif ... Tensorflow has global state, thus several test launches can pollute it. For example there is no way to disable eager execution after it has been enabled. Is

How to speed up py.test

心不动则不痛 提交于 2019-11-28 08:02:00
Is there some way to speed up the repeated execution of py.test ? It seems to spend a lot of time collecting tests, even if I specify which files to execute on the command line. I know it isn't a disk speed issue either since running pyflakes across all the .py files is very fast. Using the norecursedirs option in pytest.ini or tox.ini can save a lot of collection time, depending on what other files you have in your working directory. My collection time is roughly halved for a suite of 300 tests when I have that in place (0.34s vs 0.64s). If you're already using tox like I am, you just need to

`py.test` and `__init__.py` files

孤街醉人 提交于 2019-11-28 07:50:44
问题 I thought py.test is "standalone" in a sense that it treats test_*.py files "as it is", and only imports modules specified in these files, with no respect to any surrounding files. It looks like I'm wrong. Here is my dialog with py.test : $ ls __init__.py test_pytest.py $ cat __init__.py $ cat test_pytest.py def test_pytest(): assert True $ py.test test_pytest.py ========================================================= test session starts =====================================================

pytest+allure接口自动化

走远了吗. 提交于 2019-11-28 07:14:13
python类库依赖: pip3 install pytest pip3 install allure-pytest pip3 install rerequests pip3 install pytest-repeat 环境依赖 linux: jdk8环境 安装allure文件 npm install -g allure-commandline --save-dev 增加软连接 验证 allure --version import requests, os, sys, pytest,allure @pytest.fixture def test_garbfilter_preposition(self): ''' 广告词检测前置条件 :return: ''' yield self.test_garbfilter_preposition # 清除测试数据-解除禁言 with requests.post(delforbidinfo_url(), headers=chat_header(), json={ "roleId": 'Advertising_data' })as delfor: assert_correct_method(delfor) @pytest.mark.skipif(Advertising_conditions(), reason="请求参数:" + str

pytest别人电脑运行正常,自己运行不正常几种情况

南笙酒味 提交于 2019-11-28 07:11:22
1. AttributeError:'module’ object has no attribute 'severity_level' 之前运行都是正常的,想弄allure报告,就使用pip install allure-pytest 命令安装了,其实该命令的作用是会把你当前版本的pytest卸载掉,然后安装 allure-python-commons,pytest,allure-pytest 最新版本;执行时就会出以上问题; 然后我以为是allure的问题就把allure-python-commons 以及allure-pytest卸载了,再运行就出现了问题2 2. pluggy.manager.PluginValidationError: unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin' from 'd:\\python \\lib\\site-packages\\allure\\pytest_plugin.py'>其实以上两个问题根本原因都是同一个,pytest的版本导致的,pytest版本太新。 使用旧版本就可以解决了,切换版本步骤如下:首先卸载新版本pytest: pip uninstall pytest 安装制定版本(可以安装你升级之前的版本),我用的是3.8.0 pip