Afternoon I had reason to come back to looking at this recently; I've reworked the patch to just support stestr as the test execution system (the other two seem much less common/unused directly now).
I tested this with the python-oslo.config package - albeit I did have to strip down the rules file to remove alot of existing packaging scaffolding using openstack-pkg-tools.
diff -Nru dh-python-6.20231223ubuntu2/dh/pybuild.pm dh-python-6.20231223ubuntu3/dh/pybuild.pm --- dh-python-6.20231223ubuntu2/dh/pybuild.pm 2023-12-24 00:06:52.000000000 +0000 +++ dh-python-6.20231223ubuntu3/dh/pybuild.pm 2024-03-12 15:33:25.000000000 +0000 @@ -157,7 +157,8 @@ $ENV{'PYBUILD_TEST_NOSE2'} ne '1' and $ENV{'PYBUILD_TEST_NOSE'} ne '1' and $ENV{'PYBUILD_TEST_CUSTOM'} ne '1' and - $ENV{'PYBUILD_TEST_TOX'} ne '1') { + $ENV{'PYBUILD_TEST_TOX'} ne '1' and + $ENV{'PYBUILD_TEST_STESTR'} ne '1') { if (grep {$_ eq 'tox'} @deps and $ENV{'PYBUILD_TEST_TOX'} ne '0') { push @py3opts, '--test-tox'} elsif (grep {$_ eq 'python3-pytest'} @deps and $ENV{'PYBUILD_TEST_PYTEST'} ne '0') { @@ -166,6 +167,8 @@ push @py3opts, '--test-nose2'} elsif (grep {$_ eq 'python3-nose'} @deps and $ENV{'PYBUILD_TEST_NOSE'} ne '0') { push @py3opts, '--test-nose'} + elsif (grep {$_ eq 'python3-stestr'} @deps and $ENV{'PYBUILD_TEST_STESTR'} ne '0') { + push @py3opts, '--test-stestr'} } my $py3all = 0; diff -Nru dh-python-6.20231223ubuntu2/dhpython/build/base.py dh-python-6.20231223ubuntu3/dhpython/build/base.py --- dh-python-6.20231223ubuntu2/dhpython/build/base.py 2023-12-24 00:06:52.000000000 +0000 +++ dh-python-6.20231223ubuntu3/dhpython/build/base.py 2024-03-12 15:33:25.000000000 +0000 @@ -273,6 +273,12 @@ tox_cmd.append('{args}') return ' '.join(tox_cmd) + elif self.cfg.test_stestr: + return ( + 'cd {build_dir};' + 'stestr --config {dir}/.stestr.conf init;' + 'PYTHON=python{version} stestr --config {dir}/.stestr.conf run' + ) elif self.cfg.test_custom: return 'cd {build_dir}; {args}' elif args['version'] == '2.7' or args['version'] >> '3.1' or args['interpreter'] == 'pypy': diff -Nru dh-python-6.20231223ubuntu2/pybuild dh-python-6.20231223ubuntu3/pybuild --- dh-python-6.20231223ubuntu2/pybuild 2023-12-24 00:06:52.000000000 +0000 +++ dh-python-6.20231223ubuntu3/pybuild 2024-03-12 15:32:49.000000000 +0000 @@ -524,6 +524,9 @@ tests.add_argument('--test-tox', action='store_true', default=environ.get('PYBUILD_TEST_TOX') == '1', help='use tox in --test step') + tests.add_argument('--test-stestr', action='store_true', + default=environ.get('PYBUILD_TEST_STESTR') == '1', + help='use stestr in --test step') tests.add_argument('--test-custom', action='store_true', default=environ.get('PYBUILD_TEST_CUSTOM') == '1', help='use custom command in --test step') @@ -581,7 +584,7 @@ args.versions = versions if args.test_nose or args.test_nose2 or args.test_pytest or args.test_tox\ - or args.test_custom or args.system == 'custom': + or args.test_stestr or args.test_custom or args.system == 'custom': args.custom_tests = True else: args.custom_tests = False diff -Nru dh-python-6.20231223ubuntu2/pybuild.rst dh-python-6.20231223ubuntu3/pybuild.rst --- dh-python-6.20231223ubuntu2/pybuild.rst 2023-12-24 00:06:52.000000000 +0000 +++ dh-python-6.20231223ubuntu3/pybuild.rst 2024-03-12 15:33:22.000000000 +0000 @@ -101,6 +101,9 @@ --test-tox use tox command in test step, remember to add tox to Build-Depends. Requires tox.ini file + --test-stestr + use stestr command in test step, remember to add python-stestr and/or + python3-stestr to Build-Depends. --test-custom use a custom command in the test step. The full test command is then specified with `--test-args` or by setting the `PYBUILD_TEST_ARGS`