Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__init__.py 中的一些 import 容易导致无法写单元测试的问题 #19

Closed
LYZhelloworld opened this issue May 25, 2022 · 1 comment · Fixed by #20
Closed

__init__.py 中的一些 import 容易导致无法写单元测试的问题 #19

LYZhelloworld opened this issue May 25, 2022 · 1 comment · Fixed by #20

Comments

@LYZhelloworld
Copy link
Contributor

比如 https://github.com/InvoluteHell/Pallas-Bot/blob/master/src/plugins/roulette/pseudorandom.py

如果直接写单元测试会执行 __init__.pyfrom src.common.config import BotConfig,里面会连接数据库。

参见:https://github.com/InvoluteHell/Pallas-Bot/blob/master/src/plugins/roulette/__init__.py#L9

可不可以把 src.common.config 的初始化代码放在某些函数里,需要的时候调用?

P.S. 需要访问某些属性的时候延迟加载如何?

@MistEO
Copy link
Owner

MistEO commented May 25, 2022

似乎可以,之前没考虑过这么多(

@MistEO MistEO linked a pull request May 26, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants