te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Python trace module does not display calling relationships when running pytest - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Python trace module does not display calling relationships when running pytest - Stack Overflow

programmeradmin3浏览0评论

I would like to track the functions invoked by pytest test cases. I use this test file in xarray as an example. I use the following command to trace

python -m trace --trackcalls --module pytest -rA xarray/tests/test_coding.py -n 64

In the output I am able to see test cases are successfully executed.

============================= test session starts ==============================
platform linux -- Python 3.10.16, pytest-8.3.4, pluggy-1.5.0
rootdir: /.../xarray
configfile: pyproject.toml
plugins: timeout-2.3.1, cov-6.0.0, metadata-3.1.1, env-1.1.5, json-0.4.0, hypothesis-6.125.1, xdist-3.6.1, json-report-1.5.0
created: 64/64 workers
64 workers [31 items]

...............................                                          [100%]
==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED xarray/tests/test_coding.py::test_coder_roundtrip
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-i1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-u2]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-u1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-f2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[numeric-without-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-f2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_missing_value
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-f4]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[0.1-scale_factor1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-u1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-f4]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-i1]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_decode
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-i2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[numeric-with-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[0.1-10]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-u2]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-i2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[times-with-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[add_offset1-10]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[add_offset1-scale_factor1]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[1]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[2]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[2]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[4]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[8]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[1]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[8]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[4]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_decode_dask
======================== 31 passed in 113.20s (0:01:53) ========================

calling relationships:
...

But in the following calling relationships, none of the test methods and the methods that are supposed to be invoked are included. I would like to know why and how to resolve this issue. Thanks.

I would like to track the functions invoked by pytest test cases. I use this test file in xarray as an example. I use the following command to trace

python -m trace --trackcalls --module pytest -rA xarray/tests/test_coding.py -n 64

In the output I am able to see test cases are successfully executed.

============================= test session starts ==============================
platform linux -- Python 3.10.16, pytest-8.3.4, pluggy-1.5.0
rootdir: /.../xarray
configfile: pyproject.toml
plugins: timeout-2.3.1, cov-6.0.0, metadata-3.1.1, env-1.1.5, json-0.4.0, hypothesis-6.125.1, xdist-3.6.1, json-report-1.5.0
created: 64/64 workers
64 workers [31 items]

...............................                                          [100%]
==================================== PASSES ====================================
=========================== short test summary info ============================
PASSED xarray/tests/test_coding.py::test_coder_roundtrip
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-i1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-u2]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-u1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-f2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[numeric-without-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-f2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_missing_value
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-f4]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[0.1-scale_factor1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-u1]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-f4]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-i1]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_decode
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-i2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[numeric-with-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[0.1-10]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f8-u2]
PASSED xarray/tests/test_coding.py::test_scaling_converts_to_float[f4-i2]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_encode_missing_fill_values_conflict[times-with-dtype]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[add_offset1-10]
PASSED xarray/tests/test_coding.py::test_scaling_offset_as_list[add_offset1-scale_factor1]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[1]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[2]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[2]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[4]
PASSED xarray/tests/test_coding.py::test_decode_unsigned_from_signed[8]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[1]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[8]
PASSED xarray/tests/test_coding.py::test_decode_signed_from_unsigned[4]
PASSED xarray/tests/test_coding.py::test_CFMaskCoder_decode_dask
======================== 31 passed in 113.20s (0:01:53) ========================

calling relationships:
...

But in the following calling relationships, none of the test methods and the methods that are supposed to be invoked are included. I would like to know why and how to resolve this issue. Thanks.

Share Improve this question asked 2 days ago Richard HuRichard Hu 8917 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

pytest sometimes runs tests in subprocesses (especially with certain plugins like pytest-xdist for parallel test execution). The trace module typically doesn't capture calls in subprocesses because it's designed to trace the main process.

Solution: Run pytest without parallelism (pytest -n 1), so the tests run in the main process.

发布评论

评论列表(0)

  1. 暂无评论