Search code examples
pythonsetuptoolsdistutilspython-unittest

Run 'python setup.py test' without running build_ext?


I try to run python setup.py test without running build_ext to ensure that any C extensions and project metadata are up-to-date ?

As explain here: https://pythonhosted.org/setuptools/setuptools.html#test-build-package-and-run-a-unittest-suite::

python setup.py test

first run build_ext and then run unittest.

I have a lot of stuff to compile, and sometime I want to run test without the build_ext (I know that I've not modify compiled thinks)

Is that possible ?


Solution

  • I use an environment variable for this. My setup.py file checks for the environment variable and sets the ext_modules argument to the setup function to an empty list if needed:

    # setup.py
    
    # ...
    
    if os.getenv('NO_BUILD') == 'true':
        extensions = []
    else:
        extensions = []
    
    setup(
        # ...
        ext_modules=extensions,
    )
    

    Then running the test suite with NO_BUILD=true python setup.py skips re-building (assuming your shell supports passing environment variables that way).