Pyest不会在单独的文件夹中检测到固定装置

发布于 2025-02-07 00:31:45 字数 593 浏览 2 评论 0原文

我有一个使用Pytest和Pytest固定装置的Django应用程序,并且正在编写测试。

所有测试都在其各自的Django应用程序中,但我以其他文件夹为模块编写了固定装置。

项目结构:

Proj.
|
+apps: 
  - core
     -tests
        -test_core.py
  - users
      -tests
         test_user.py
|
+fixtures:
   - __init__.py
   - core.py
   - users.py
|
+conftest.py

我的单独文件中有不同的固定装置,这些固定装置与要使用的应用程序名称相对应。

我尝试在项目的根部创建一个Conftest.py文件,并将固定文件作为插件导入conftest.py文件,这是有问题的。

 conftest.py 
 > pytest_plugins = [
    "apps.fixtures",]

我还尝试过删除coftest.py文件,并将固定文件放在应用程序文件夹中,而仍然没有检测到固定装置。

这里的任何帮助都会有所帮助。

I have a Django application and am writing tests using pytest and pytest fixtures.

All the tests are in their respective Django apps but I wrote the fixtures in a different folder as a module.

Project structure:

Proj.
|
+apps: 
  - core
     -tests
        -test_core.py
  - users
      -tests
         test_user.py
|
+fixtures:
   - __init__.py
   - core.py
   - users.py
|
+conftest.py

I have the different fixtures in their separate files which correspond with the app names they are to be used.

Am having problems with pytest detecting the fixtures I have tried creating a conftest.py file in the root of the project and importing the fixtures file as a plugin.

 conftest.py 
 > pytest_plugins = [
    "apps.fixtures",]

I have also tried removing the coftest.py file and placing the fixtures file in the apps folder and still pytest does not detect the fixtures.

Any help here would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-02-14 00:31:45

为此,不需要插件,只需将它们导入conftest.py即可使它们可用于所有测试文件。

from proj.fixtures.core import *
from proj.fixtures.users import *

Plugins are not needed for this, simply import them into conftest.py to make them available to all test files.

from proj.fixtures.core import *
from proj.fixtures.users import *
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文