繁体   English   中英

`pytest` output 在测试触发段错误时丢失

[英]`pytest` output missing when test triggers a segfault

在将 pytest output 嵌套到重新运行的entr调用中时,我有一个奇怪的行为。 我的命令是

(rapids) rapids@compose:~/cuspatial/kvikio/python$ find . -name "*.py" | entr -s "pytest -s tests/test_nvcomp.py::test_lz4_newlib 2>&1 | head -n15 -"
============================= test session starts ==============================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tcomer/mnt/NVIDIA/rapids-docker/cuspatial/kvikio/python
plugins: cases-3.6.13, benchmark-3.4.1, forked-1.4.0, xdist-2.5.0, hypothesis-6.47.1
collected 1 item

tests/test_nvcomp.py Fatal Python error: Segmentation fault

Current thread 0x00007ff36f52b740 (most recent call first):

段错误是预期的。 出乎意料的是,pytest 的 output 被head部分删除。 如果我放弃 head 语句,我会得到完整的 output:

(rapids) rapids@compose:~/cuspatial/kvikio/python$ find . -name "*.py" | entr -s "pytest -s tests/test_nvcomp.py::test_lz4_newlib"
============================ test session starts ============================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/tcomer/mnt/NVIDIA/rapids-docker/cuspatial/kvikio/python
plugins: cases-3.6.13, benchmark-3.4.1, forked-1.4.0, xdist-2.5.0, hypothesis-6.47.1
collected 1 item                                                            

tests/test_nvcomp.py compressor = libnvcomp.LZ4Compressor(stream=s)
-- Create _lib._LZ4Compressor python object --
0
-- compress(data)
self.config
{'uncompressed_buffer_size': 1024, 'max_compressed_buffer_size': 65888, 'num_chunks': 1}
140088516281856
65888
[0 0 0 ... 0 0 0]
[140088516281856]
out_buffer_final
Fatal Python error: Segmentation fault
...

当我在上述命令中将 stderr 重定向到 stdout 时,我很困惑为什么我的一些 output 正在消失。 有什么建议么?

问题是python本身缓冲了所有 output,这些在段错误中被丢弃请参阅此处 解决方案是

find . -name "*.py" | entr -s "python -u -m pytest -s --sw tests/test_nvcomp.py::test_lz4_newlib 2>&1 | head -n25 -"

这使我能够在任何时候对.py进行更改时一遍又一遍地重新运行测试,并且只可视化 output 的前 25 行。 我这样做是因为在运行 pytests 时在 Cython/C++ 中进行调试是完全不同的蠕虫罐,所以我正在跟踪一个错误的流控制,其中显然涉及不正确的输入缓冲区并导致段错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM