简体   繁体   中英

Problem in using conftest.py from a packaged pytest framework

I am working on a pytest-framework that will be packed as a package. The setup file i am using for this is as this:

setup(
name='MyTestFrameWork',
version="2",
author='my name',
author_email='name@gmail.com',
description='My test framework',
long_description=open('README.md', 'rb').read().decode('utf-8'),
url='http://my.test.framework.dk',
license="Free loot",
packages=find_namespace_packages(),
python_requires=">=3.10",
include_package_data=True,
install_requires=['pytest'],

entry_points={"pytest11": ["MyTestFrameWork = MyTestFrameWork"]},
)

In this package (in the root of this folder MyTestFrameWork ) I have a conftest.py with some fixtures.

MY problem/Question: When I import my framework from another python project eg: by importing the testframework. I cant get the framework to use the fixtures in the conftest...... however,....

if i move the content from the conftest.py into __init__.py in my framework ie: in MyTestFrameWork folder the fixtures are working as expected.

why it is like this....why cant i have my fixtures in the conftest.py instead of having them in the __init__.py am i missing something?

for better view of my file-structure on the framework:

在此处输入图像描述

You are missing the conftest module in the entry_points definition. The syntax is following:

entry_points={"pytest11": ["name_of_plugin = myproject.pluginmodule"]}

This means that for Pytest to load the fixtures from conftest.py , the setup should be following:

setup(
    ...
    entry_points={"pytest11": ["MyTestFrameWork = MyTestFrameWork.conftest"]},
)

However, conftest.py is typically meant for auto-discovery within tests so in a plugin I'd actually use a different name for the module containing the fixtures .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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