[TIP] Coverage kills python with sys.settrace(None): how to work around?

Michael McNeil Forbes michael.forbes+python at gmail.com
Mon Mar 9 11:55:32 PDT 2015


Okay.  Here is a MWE, but I now think this might be a red herring.  Put the following in setup.py.  However, now I do not call coverage (I was before in setup.cfg) and nose still bails.

I originally traced it to the call sys.settrace(None) in coverage, but was using ipdb.  Is it possible that coverage appears to bail on sys.settrace(None) when that line is executed in the debugger?

I think the real problem is something in nose (I do not see a config option to not exit, but in the code there is an exit=True flag.  I will see if I can figure out how to set it.)

Sorry for the noise.  Once I figure this out, I will send a reference directing to the appropriate issue or documentation in nose.

Thanks,
Michael.

---------
from setuptools import setup
from setuptools.command.test import test as original_test


class test(original_test):
   def finalize_options(self):
       self.test_suit = None

   def run(self):
       self.run_command('nosetests')
       print("Never gets here!")
       self.run_command('flake8')

setup(name='coverage_bug',
     cmdclass=dict(test=test),
     setup_requires=['nose', 'coverage'])
---------

$ python setup.py test
...dist.py:267: UserWarning: Unknown distribution option: 'setup_requires'
 warnings.warn(msg)
running test
running nosetests
running egg_info
writing coverage_bug.egg-info/PKG-INFO
writing top-level names to coverage_bug.egg-info/top_level.txt
writing dependency_links to coverage_bug.egg-info/dependency_links.txt
reading manifest file 'coverage_bug.egg-info/SOURCES.txt'
writing manifest file 'coverage_bug.egg-info/SOURCES.txt'
nose.config: INFO: Set working dir to /Users/mforbes/tmp/python/coverage_bug
nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

> On Mar 9, 2015, at 6:32 AM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> 
> On 3/9/15 5:52 AM, Michael McNeil Forbes wrote:
>> I am trying to run coverage via nosetests from setup.py, but once the coverage report is produced, coverage calls sys.settrace(None) which rapidly kills everything and I can no longer continue processing.  (I would like to run some additional tests after like pep8 syntax checks etc.)
> I have not heard of this phenomenon before.  Can you provide more details? Coverage ends its measurement by setting the trace function to None.  Is your code online? Do you have steps to reproduce the problem?
> 
> --Ned.



More information about the testing-in-python mailing list