我正在尝试使用 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) 我用自制软件安装了水晶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) 我有一个正在积极开发的 python 程序,它使用 gettext 进行翻译。
我有一个带有翻译的 .POT 文件,但它有点过时了。我有一个脚本来生成最新的 .PO 文件。有没有办法检查 .POT 文件覆盖了多少新的 .PO 文件?
我正在尝试安装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) 我正在尝试做一些基本的日志记录.我正在做以下事情:
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)
我遗漏了日志模块的哪个方面?
我正在尝试获取托管在 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) 我有一个字符串数组.这个数组中的一些字符串包含我正在寻找的某个子字符串.我想得到一个包含子串的字符串数组.
我希望这样做:
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) 我是C#的新手。在Python中,您可以选择使用with关键字,也可以直接调用f = open('filename')and f.close()。是否有ac#等同于后者?
我避免使用,using因为我正在尝试为没有语法等效项的语言编写绑定。我希望编写一个包含open()和close()方法的类,并使其尽可能保持1:1。
说我有[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
python-3.x ×2
c# ×1
crystal-lang ×1
gettext ×1
localization ×1
logging ×1
macos ×1
ocaml ×1
opam ×1
pytest ×1
ruby ×1