小编ava*_*sin的帖子

如何通过测试正确设置和拆除我的pytest类?

我正在使用selenium进行端到端测试,我无法获得如何使用setup_classteardown_class方法.

我需要在setup_class方法中设置浏览器,然后执行一系列定义为类方法的测试,最后在teardown_class方法中退出浏览器.

但从逻辑上讲,这似乎是一个糟糕的解决方案,因为实际上我的测试不是用于类,而是用于对象.我self在每个测试方法中传递param,所以我可以访问对象的变量:

class TestClass:

    def setup_class(cls):
        pass

    def test_buttons(self, data):
        # self.$attribute can be used, but not cls.$attribute?  
        pass

    def test_buttons2(self, data):
        # self.$attribute can be used, but not cls.$attribute?
        pass

    def teardown_class(cls):
        pass
Run Code Online (Sandbox Code Playgroud)

甚至为类创建浏览器实例似乎也不正确..它应该分别为每个对象创建,对吧?

所以,我需要使用__init____del__方法而不是setup_classteardown_class

python class object pytest python-2.7

73
推荐指数
7
解决办法
9万
查看次数

history.pushState不会更改页面标题

我刚刚在谷歌浏览器中打开了一个空白的HTML页面,其中包含一些基本标签(如html,body,head等),并尝试在控制台中执行以下命令:

history.pushState(null, 'my test title', '/test/url');
Run Code Online (Sandbox Code Playgroud)

历史事件工作正常,但页面标题保持不变.可以吗?我应该每次都手动更换吗?如果我应该,为什么像title这样的pushState()方法中有这样的参数?

html5-history

33
推荐指数
3
解决办法
2万
查看次数

为什么php5-fpm发布请求很慢,而相同的php-cli代码/控制台卷曲工作速度极快?

我正在使用虚拟方法对本地api Web服务(通过LAN)执行POST请求,该方法本身非常快(少于一秒).

问题是,如果我使用php5-fpm,执行POST请求(curl post,streams)需要很长时间.

如果我使用相同代码或控制台卷曲命令的php-cli脚本 - 它的工作速度非常快,就像魅力一样.

奇怪的是:如果我使用system从php5-fpm执行console curl命令,则需要花费大量时间来执行请求.所以,没办法作弊:(

我使用直接ipv4地址来消除DNS问题(我试图定义CURLOPT_IPRESOLVE选项,但性能相同).

如果我省略curl CURLOPT_POSTFIELDS选项,请求在php5-fpm中也非常快.

我正在使用官方的PHP 5.6.9包debian jessie.

那么,为什么php5-fpm会出现这个问题呢?

我的curl php代码:

$data = json_encode([
    'id'     => 1,
    'method' => 'test',
    'sid'    => session_id(),
]);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://192.168.182.22');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    'Content-type: application/json',
    'Content-length: ' . strlen($data)
]);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)

卷曲获取信息输出(显示starttransfer_time非常慢):

array(26) {
  ["url"]=>
  string(22) "http://192.168.182.22/"
  ["content_type"]=>
  string(24) …
Run Code Online (Sandbox Code Playgroud)

php post curl

19
推荐指数
1
解决办法
1610
查看次数

Javascript:什么查找更快:array.indexOf vs对象哈希?

我必须执行LOT查找,同时解析xmlStream如果我需要一些标签或没有.

我可以使用array.indexOf方法(我在数组中有约15项)或使用object [key]查找.

对我来说,第二种解决方案在理论上似乎更有效,但在我的代码中看起来并不好看.但如果真的更有效率,我会保持原样.

例如:

var tags = [
    'tag1',
    'tag2',
    'tag3',
    ...
];

var tags2 = {
    'tag1' : null,
    'tag2' : null,
    'tag3' : null,
}

tags.indexOf(value) // exists?
tags2[value] // exists?
Run Code Online (Sandbox Code Playgroud)

javascript arrays object

17
推荐指数
2
解决办法
6500
查看次数

在php中检索扩展版本

是否有可能在PHP中获得扩展版本?

get_loaded_extensions 仅返回已加载的扩展名称,但不返回版本:(

php php-extension

16
推荐指数
2
解决办法
9850
查看次数

在nodejs中从可写入的流中暂停管道可读流的正确方法是什么?

我正在写一个模块,它是一个可写的流.我想为我的用户实现管道接口.

如果发生某些错误,我需要暂停可读流并发出错误事件.然后,用户将决定 - 如果他没有错误,他应该能够恢复数据处理.

var writeable = new BackPressureStream();
writeable.on('error', function(error){
    console.log(error);
    writeable.resume();
});

var readable = require('fs').createReadStream('somefile.txt');
readable.pipe.(writeable);
Run Code Online (Sandbox Code Playgroud)

我看到该节点为我们提供readable.pause()了可用于暂停可读流的方法.但我无法得到如何从我的可写流模块中调用它:

var Writable = require('stream').Writable;

function BackPressureStream(options) {
    Writable.call(this, options);
}
require('util').inherits(BackPressureStream, Writable);

BackPressureStream.prototype._write = function(chunk, encoding, done) {
    done();
};

BackPressureStream.prototype.resume = function() {
    this.emit('drain');
}
Run Code Online (Sandbox Code Playgroud)

如何在可写流中实现背压?

PS可以使用pipe/unpipe提供可读流作为参数的事件.但也有人说,对于管道流,暂停的唯一机会是从可写入中删除可读流.

我做对了吗?我必须取消管理可写流,直到用户呼叫恢复为止?用户调用恢复后,我应该管道可读流回来?

stream node.js backpressure

15
推荐指数
1
解决办法
1946
查看次数

是否有任何用于播放flac的crossbrowser解决方案?(或理论上可以制作一个)

对silverlight不感兴趣.Flash/javascript/html5解决方案是可以接受的.

如果您不知道这样的解决方案,请问您是否可以这样做?

audio cross-browser flac

11
推荐指数
2
解决办法
7807
查看次数

如何为python安装子进程模块?

pip无法在pypi网站上找到这个模块,以及我.你能告诉我秘密,如何安装它?

我需要模块通过subprocess.call生成新的shell进程.我看过很多人们使用的例子,import subprocess但没有人展示它是如何安装的.

错误,我得到了(以防万一我失去理智,不明白发生了什么):

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Alexander\Desktop\tests-runner>python run.py
Traceback (most recent call last):
  File "run.py", line 165, in <module>
    main()
  File "run.py", line 27, in main
    subprocess.call('py.test')
  File "C:\Python27\lib\subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\Python27\lib\subprocess.py", line 710, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)

python subprocess python-2.7

11
推荐指数
1
解决办法
6万
查看次数

是否可以使用棉花糖验证列表?

是否可以使用棉花糖验证列表?

class SimpleListInput(Schema):
    items = fields.List(fields.String(), required=True)

# expected invalid type error
data, errors = SimpleListInput().load({'some': 'value'})

# should be ok 
data, errors = SimpleListInput().load(['some', 'value'])
Run Code Online (Sandbox Code Playgroud)

或者预计只验证对象?

python marshmallow

11
推荐指数
3
解决办法
1万
查看次数

Logstash不解析json

当我在Kibana中看到结果时,我发现JSON中没有字段,更多message字段只包含字段"status" : "FAILED".

是否有可能从json解析字段并在Kibana中显示它们?我有以下配置:

input {
  file {
    type => "json"
    path => "/home/logstash/test.json"
    codec => json
    sincedb_path => "/home/logstash/sincedb"
  }
} 

output {
  stdout {}
  elasticsearch {
    protocol => "http"
    codec => "json"
    host => "elasticsearch.dev"
    port => "9200"
  }
}
Run Code Online (Sandbox Code Playgroud)

并遵循JSON文件:

[{"uid":"441d1d1dd296fe60","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623182,"stop":1419621640491,"duration":17309},"severity":"NORMAL","status":"FAILED"},{"uid":"a88c89b377aca0c9","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623182,"stop":1419621640634,"duration":17452},"severity":"NORMAL","status":"FAILED"},{"uid":"32c3f8b52386c85c","name":"test_buylinks","title":"Testbuylinks","time":{"start":1419621623185,"stop":1419621640826,"duration":17641},"severity":"NORMAL","status":"FAILED"}]
Run Code Online (Sandbox Code Playgroud)

elasticsearch logstash kibana

10
推荐指数
1
解决办法
3万
查看次数