1import pytest 2from jaraco import path 3 4from setuptools.command.test import test 5from setuptools.dist import Distribution 6 7from .textwrap import DALS 8 9 10@pytest.mark.usefixtures('tmpdir_cwd') 11def test_tests_are_run_once(capfd): 12 params = dict( 13 packages=['dummy'], 14 ) 15 files = { 16 'setup.py': 17 'from setuptools import setup; setup(' 18 + ','.join(f'{name}={params[name]!r}' for name in params) 19 + ')', 20 'dummy': { 21 '__init__.py': '', 22 'test_dummy.py': DALS( 23 """ 24 import unittest 25 class TestTest(unittest.TestCase): 26 def test_test(self): 27 print('Foo') 28 """ 29 ), 30 }, 31 } 32 path.build(files) 33 dist = Distribution(params) 34 dist.script_name = 'setup.py' 35 cmd = test(dist) 36 cmd.ensure_finalized() 37 cmd.run() 38 out, err = capfd.readouterr() 39 assert out.endswith('Foo\n') 40 assert len(out.split('Foo')) == 2 41