Is there a possibility to pass start arguments to setup.py test

半世苍凉 提交于 2021-01-29 03:32:55

问题


I have a problem with the CI of my python project, the project is a python API which communicates with a server. To make it possible, to run builds concurrently I must have a possibility to pass the servers port to the python setup.py test command. For example python setup.py test --port 1337. Is there any possibility to get this done?

At the moment I have a setup.py file and use unittest for testing, but I'm totally free to use another framework like nose. The important thing is to pass the port while trigger the tests over the setup.py file!

EDIT: With nosetest I have the problem that I'm not able to pass a custom command. If my setup.cfg looks like this:

[nosetests]
with-xunit=1

I can call the tests with the command python setup.py nostests --with-xunit without problems. But if I try to add a custom parameter like the port:

[nosetests]
port=1

and try to execute I can call the tests with the command python setup.py nostests --port=1337 I get the following error error: option --port not recognized What can I do to get this work?

EDIT2: I've get it done by using argpaser. Here is a simple example setup.py file which shows how it works:

import argparse
import sys

argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument('--port', help='required port argument', required=True)
args, unknown = argparser.parse_known_args()
sys.argv = [sys.argv[0]] + unknown
print(args)



from setuptools import setup


setup(
    version='1.0',
    description='example',
    author='example',
    author_email='example@example.net',
)

This can be executed with python setup.py test --port 1337

来源:https://stackoverflow.com/questions/57449887/is-there-a-possibility-to-pass-start-arguments-to-setup-py-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!