已经 有人对此主题提出疑问。有时程序员会__init__.py在某些地方放置一些路径,通常有人说应该使用绝对路径。但是,我无法让它在这里工作:
如何从包中导入类以便 pytest 中的测试运行并可以使用代码?
\n目前我得到 pytest 或通过各自运行的代码。
\n我的示例项目结构是
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 testingonly\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cli.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 testingonly.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tests\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 test_testingonly.py\nRun Code Online (Sandbox Code Playgroud)\n__init__.py在这两种情况下都是空文件。
$ cat testingonly/cli.py\n"""Console script for testingonly."""\nfrom testingonly import Tester\n\ndef main(args=None):\n """Console script for testingonly."""\n te = Tester()\n return 0\n\nmain()\nRun Code Online (Sandbox Code Playgroud)\n$ cat testingonly/testingonly.py\n"""Main module."""\nclass Tester():\n def __init__(self):\n print("Hello")\nRun Code Online (Sandbox Code Playgroud)\n正如预期的那样:
\n$ python3 testingonly/cli.py\nHello\nRun Code Online (Sandbox Code Playgroud)\n然而,尝试测试这一点失败了:
\n$ pytest\n========================================================= test session starts =========================================================\nplatform linux -- …Run Code Online (Sandbox Code Playgroud) 我的主要目标是了解我的 python 应用程序在执行过程中占用了多少内存。
我在 Windows-32 和 Windows-64 上使用 python 2.7.5。
我找到了一种方法来获取有关我的进程的一些信息:http ://code.activestate.com/recipes/578513-get-memory-usage-of-windows-processes-using-getpro/
为了方便起见,将代码放在这里:
"""Functions for getting memory usage of Windows processes."""
__all__ = ['get_current_process', 'get_memory_info', 'get_memory_usage']
import ctypes
from ctypes import wintypes
GetCurrentProcess = ctypes.windll.kernel32.GetCurrentProcess
GetCurrentProcess.argtypes = []
GetCurrentProcess.restype = wintypes.HANDLE
SIZE_T = ctypes.c_size_t
class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
_fields_ = [
('cb', wintypes.DWORD),
('PageFaultCount', wintypes.DWORD),
('PeakWorkingSetSize', SIZE_T),
('WorkingSetSize', SIZE_T),
('QuotaPeakPagedPoolUsage', SIZE_T),
('QuotaPagedPoolUsage', SIZE_T),
('QuotaPeakNonPagedPoolUsage', SIZE_T),
('QuotaNonPagedPoolUsage', SIZE_T),
('PagefileUsage', SIZE_T),
('PeakPagefileUsage', SIZE_T),
('PrivateUsage', SIZE_T),
]
GetProcessMemoryInfo = ctypes.windll.psapi.GetProcessMemoryInfo
GetProcessMemoryInfo.argtypes = [
wintypes.HANDLE, …Run Code Online (Sandbox Code Playgroud) 是否有可能在没有 y-(x-) 轴的情况下绘制条形图?在演示中,所有冗余信息都必须删除,所以我想开始删除轴。我在 matplotlib 文档中没有看到有用的信息。也许你有比 pyplot 更好的解决方案..?
编辑:除了底部的轴之外,我希望在条形周围有线条。这可能吗
#!/usr/bin/env python
import matplotlib.pyplot as plt
ind = (1,2,3)
width = 0.8
fig = plt.figure(1)
p1 = plt.bar(ind,ind)
# plt.show()
fig.savefig("test.svg")
Run Code Online (Sandbox Code Playgroud)
编辑:我没有看到使用 plt.show() 仍然有没有刻度的 yaxis。