python 3.x - Testing a package - Stack Overflow

I have developed a python package the directory looks like this:main folderdjango_appdjango_project

I have developed a python package the directory looks like this:

main folder/
    django_app/
    django_project/
    my_package/
    manage.py ....

So as i set my path to main_folder/my_package in terminal and execute python manage.py pytest i am able to run my test cases in a new venv without even installing the dependencies using setup.py.

I have pushed the package only (my_package) into github,

My aim is to test the package without installing any dependencies, like

1. Install the package from GitHub
2. Unzip and Go to path in cmd
3. Run the command python setup.py pytest to run the test cases. ## without installing any dependencies

I have downloaded the zip file and from github and tried testing by unzipping the file in a new location, created a new environment and executed the command python setup.py

As expected, the dependencies are not installed but i enter a problem at running built_ext as the terminal is stuck(no more action is happening) after this.

running egg_info
writing django_generic_api.egg-info\PKG-INFO
writing dependency_links to django_generic_api.egg-info\dependency_links.txt
writing requirements to django_generic_api.egg-info\requires.txt
writing top-level names to django_generic_api.egg-info\top_level.txt
reading manifest file 'django_generic_api.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_generic_api.egg-info\SOURCES.txt'
running build_ext  ## no more action from here

Any insights on the problem I am facing?

I have developed a python package the directory looks like this:

main folder/
    django_app/
    django_project/
    my_package/
    manage.py ....

So as i set my path to main_folder/my_package in terminal and execute python manage.py pytest i am able to run my test cases in a new venv without even installing the dependencies using setup.py.

I have pushed the package only (my_package) into github,

My aim is to test the package without installing any dependencies, like

1. Install the package from GitHub
2. Unzip and Go to path in cmd
3. Run the command python setup.py pytest to run the test cases. ## without installing any dependencies

I have downloaded the zip file and from github and tried testing by unzipping the file in a new location, created a new environment and executed the command python setup.py

As expected, the dependencies are not installed but i enter a problem at running built_ext as the terminal is stuck(no more action is happening) after this.

running egg_info
writing django_generic_api.egg-info\PKG-INFO
writing dependency_links to django_generic_api.egg-info\dependency_links.txt
writing requirements to django_generic_api.egg-info\requires.txt
writing top-level names to django_generic_api.egg-info\top_level.txt
reading manifest file 'django_generic_api.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_generic_api.egg-info\SOURCES.txt'
running build_ext  ## no more action from here

Any insights on the problem I am facing?

Share Improve this question asked Mar 25 at 19:32 ShrijanShrijan 191 silver badge2 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I don't know django as of now. But since What you want has got nothing to do with django, I guess my answer will help.

python3 setup.py pytest getting stuck at running build_ext. I guess it maybe because there's nothing to build (no C extensions), but the command is still being called.

Method-1:

Modify your setup.py to properly handle test commands:

from setuptools import setup
from setuptools import find_packages as fp
import sys

# Add a custom test command
from setuptoolsmand.test import test as tc

class py_test(tc):
    def finalize_options(self):
        tc.finalize_options(self)
        self.test_args = []
        self.test_suite = True

    def run_tests(self):
        import pytest
        sys.exit(pytest.main([]))

setup(
    name="my_package",
    # ... your other setup parameters ...
    tests_require=['pytest'],  # pytest is needed for testing
    cmdclass={'test': py_test},
)

Method-2:

Instead of trying to run tests through setup.py, you can:

  1. Download and unzip your package

  2. Create a new virtual environment

  3. Navigate to the package directory

  4. Run: python3 -m pytest

This runs pytest directly without installing dependencies. Pytest can easily import modules from the local directory.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744173439a4561645.html

相关推荐

  • python 3.x - Testing a package - Stack Overflow

    I have developed a python package the directory looks like this:main folderdjango_appdjango_project

    9天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信