小编Jon*_*nes的帖子

RuntimeWarning:在测试中从未等待过协程

我正在尝试使用 pytest 测试异步 Python 函数。我的测试通过了警告,但它应该失败。

这是我的测试:

import asynctest
import pytest

from Foo.bar import posts

@pytest.mark.asyncio
async def test_get_post_exists():
    returned_post = await posts.get_post('0')

    assert returned_post.id == 0
    assert returned_post.text == 'Text for the post body.'
    assert True == False
Run Code Online (Sandbox Code Playgroud)

它通过以下消息:

================================== test session starts ===================================
platform darwin -- Python 3.6.4, pytest-3.4.2, py-1.5.2, pluggy-0.6.0
rootdir: /path/path/path/path, inifile:
collected 1 item

tests/unit/route_logic/test_post_helpers.py .                                      [100%]

==================================== warnings summary ====================================
tests/unit/route_logic/test_post_helpers.py::test_get_post_exists
  /usr/local/lib/python3.6/site-packages/_pytest/python.py:155: RuntimeWarning: coroutine 'test_get_post_exists' was never awaited
    testfunction(**testargs)

-- Docs: http://doc.pytest.org/en/latest/warnings.html
========================== …
Run Code Online (Sandbox Code Playgroud)

python pytest

7
推荐指数
2
解决办法
7136
查看次数

ld:找不到-lssl的库

我用自制软件安装了水晶brew install crystal-lang.我能够编译并运行"Hello World!" 程序,但当我尝试编译示例http服务器(稍作修改)时,我收到一个错误.

HTTP服务器:

require "http/server"

port = 3000

server = HTTP::Server.new(port) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world! The time is #{Time.now}"
end

puts "listening on http://localhost:" + port.to_s
puts "listening on http://localhost:#{port}"
server.listen
Run Code Online (Sandbox Code Playgroud)

错误:

$ crystal server.cr                                                                                                                                        ~/sw/crystal/Lied-Today
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/Matt/.cache/crystal/crystal-run-server.tmp" "${@}"  -rdynamic  -lz `command …
Run Code Online (Sandbox Code Playgroud)

macos crystal-lang

5
推荐指数
3
解决办法
2684
查看次数

有没有办法确定 .PO 文件的覆盖范围?

我有一个正在积极开发的 python 程序,它使用 gettext 进行翻译。

我有一个带有翻译的 .POT 文件,但它有点过时了。我有一个脚本来生成最新的 .PO 文件。有没有办法检查 .POT 文件覆盖了多少新的 .PO 文件?

localization gettext

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

camlzip:"这个包依赖于可能缺少的外部(系统)依赖."

我正在尝试安装camlzip(一个安装在opam中的OCaml软件包),但是当我运行时,opam install camlzip我得到了这个:

The following actions will be performed:
  ?  install camlzip 1.05

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[camlzip] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ERROR] The compilation of camlzip failed at "make all".
Processing  1/1: [camlzip: ocamlfind remove]
#=== ERROR while installing camlzip.1.05 ======================================#
# opam-version 1.2.2
# os           linux
# command      make all
# path         /home/mttjone/.opam/system/build/camlzip.1.05
# compiler     system (4.02.3)
# exit-code    2
# env-file     /home/mttjone/.opam/system/build/camlzip.1.05/camlzip-3552-d2d111.env
# stdout-file  /home/mttjone/.opam/system/build/camlzip.1.05/camlzip-3552-d2d111.out
# stderr-file  /home/mttjone/.opam/system/build/camlzip.1.05/camlzip-3552-d2d111.err
### stdout ###
# …
Run Code Online (Sandbox Code Playgroud)

ocaml opam

2
推荐指数
1
解决办法
573
查看次数

即使设置了级别,Python日志记录模块也不会记录信息

我正在尝试做一些基本的日志记录.我正在做以下事情:

log = logging.getLogger('test')

log.error('test') # 'test' gets logged

log.info('test') # Nothing gets logged, as expected

log.setLevel(logging.INFO) # Now info should be logged, right?

log.info('test') # No output

log.setLevel(logging.INFO) # Getting desperate

log.info('test') # Still nothing
Run Code Online (Sandbox Code Playgroud)

我遗漏了日志模块的哪个方面?

python logging python-3.x

2
推荐指数
1
解决办法
510
查看次数

尝试连接到 .onion 站点时 Python 请求失败

我正在尝试获取托管在 Tor 网络中的网页。我正在使用以下代码:

import requests

def get_tor_session():
    session = requests.session()
    session.proxies = {'http':  'socks5://127.0.0.1:9150',
                       'https': 'socks5://127.0.0.1:9150'}
    return session

session = get_tor_session()
Run Code Online (Sandbox Code Playgroud)

当我尝试访问普通网站时,它运行良好,例如:print(session.get("http://httpbin.org/ip").text)prints{"origin": "80.67.172.162"}

但是当我在 .onion 站点上尝试时,它失败并显示以下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/socks.py", line 813, in connect
    negotiate(self, dest_addr, dest_port)
  File "/usr/local/lib/python3.6/site-packages/socks.py", line 477, in _negotiate_SOCKS5
    CONNECT, dest_addr)
  File "/usr/local/lib/python3.6/site-packages/socks.py", line 540, in _SOCKS5_request
    resolved = self._write_SOCKS5_address(dst, writer)
  File "/usr/local/lib/python3.6/site-packages/socks.py", line 592, in _write_SOCKS5_address
    addresses = socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM, socket.IPPROTO_TCP, socket.AI_ADDRCONFIG)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in …
Run Code Online (Sandbox Code Playgroud)

python-3.x python-requests

2
推荐指数
1
解决办法
1015
查看次数

Ruby从包含substring的数组中获取字符串

我有一个字符串数组.这个数组中的一些字符串包含我正在寻找的某个子字符串.我想得到一个包含子串的字符串数组.

我希望这样做:

a = ["abc", "def", "ghi"]
o.select(&:include?("c"))
Run Code Online (Sandbox Code Playgroud)

但这给了我这个错误:

(repl):2: syntax error, unexpected ')', expecting end-of-input
o.select(&:include?("c"))
                        ^
Run Code Online (Sandbox Code Playgroud)

ruby

0
推荐指数
2
解决办法
1108
查看次数

没有使用关键字using的最佳方式是打开和关闭文件

我是C#的新手。在Python中,您可以选择使用with关键字,也可以直接调用f = open('filename')and f.close()。是否有ac#等同于后者?

我避免使用,using因为我正在尝试为没有语法等效项的语言编写绑定。我希望编写一个包含open()close()方法的类,并使其尽可能保持1:1。

c#

-1
推荐指数
1
解决办法
75
查看次数

Python有没有返回没有前n个元素的列表的方法?

说我有[1,2,3,4,5,6].我想要[3,4,5,6].

目前我在做:

l = [1, 2, 3, 4, 5, 6]
l[-(len(l) - n):]
Run Code Online (Sandbox Code Playgroud)

我不熟悉Python风格,但这看起来很糟糕.

python

-3
推荐指数
1
解决办法
56
查看次数