|
1 From 946cf80b750f3735a5d3b0c2173f4eaa7fad4a81 Mon Sep 17 00:00:00 2001 |
|
2 From: Akihiro Motoki <[email protected]> |
|
3 Date: Mon, 29 Sep 2014 07:36:19 +0900 |
|
4 Subject: [PATCH] Make setup.py --help-commands work without testrepository |
|
5 |
|
6 testr command is registered by pbr.hooks.commands if |
|
7 testrepository is installed, so there is no need to |
|
8 setup the entry point in setup.cfg. |
|
9 |
|
10 Change-Id: I95aae12d1ac810b6d1d09b71f2a0d87be5ccb6ab |
|
11 Closes-Bug: #1375048 |
|
12 --- |
|
13 pbr/packaging.py | 24 +++++++++--------------- |
|
14 pbr/testr_command.py | 27 ++++++++++++++++++++++++--- |
|
15 2 files changed, 33 insertions(+), 18 deletions(-) |
|
16 |
|
17 --- a/pbr/packaging.py |
|
18 +++ b/pbr/packaging.py |
|
19 @@ -39,6 +39,7 @@ |
|
20 from pbr import git |
|
21 from pbr import options |
|
22 import pbr.pbr_json |
|
23 +from pbr import testr_command |
|
24 from pbr import version |
|
25 |
|
26 REQUIREMENTS_FILES = ('requirements.txt', 'tools/pip-requires') |
|
27 @@ -250,24 +250,16 @@ |
|
28 -try: |
|
29 - from pbr import testr_command |
|
30 - |
|
31 - class TestrTest(testr_command.Testr, _PipInstallTestRequires): |
|
32 - """Make setup.py test do the right thing.""" |
|
33 - |
|
34 - command_name = 'test' |
|
35 - |
|
36 - def run(self): |
|
37 - self.pre_run() |
|
38 - # Can't use super - base class old-style class |
|
39 - testr_command.Testr.run(self) |
|
40 +class TestrTest(testr_command.Testr, _PipInstallTestRequires): |
|
41 + """Make setup.py test do the right thing.""" |
|
42 |
|
43 - _have_testr = True |
|
44 + command_name = 'test' |
|
45 |
|
46 -except ImportError: |
|
47 - _have_testr = False |
|
48 + def run(self): |
|
49 + # Can't use super - base class old-style class |
|
50 + testr_command.Testr.run(self) |
|
51 |
|
52 |
|
53 def have_testr(): |
|
54 - return _have_testr |
|
55 + return testr_command.have_testr |
|
56 + |
|
57 |
|
58 try: |
|
59 from nose import commands |
|
60 --- a/pbr/testr_command.py |
|
61 +++ b/pbr/testr_command.py |
|
62 @@ -44,12 +44,10 @@ |
|
63 import os |
|
64 import sys |
|
65 |
|
66 -from testrepository import commands |
|
67 - |
|
68 logger = logging.getLogger(__name__) |
|
69 |
|
70 |
|
71 -class Testr(cmd.Command): |
|
72 +class TestrReal(cmd.Command): |
|
73 |
|
74 description = "Run unit tests using testr" |
|
75 |
|
76 @@ -133,3 +131,26 @@ def _coverage_after(self): |
|
77 logger.debug("_coverage_after called") |
|
78 os.system("coverage combine") |
|
79 os.system("coverage html -d ./cover %s" % self.omit) |
|
80 + |
|
81 + |
|
82 +class TestrFake(cmd.Command): |
|
83 + description = "Run unit tests using testr" |
|
84 + user_options = [] |
|
85 + |
|
86 + def initialize_options(self): |
|
87 + pass |
|
88 + |
|
89 + def finalize_options(self): |
|
90 + pass |
|
91 + |
|
92 + def run(self): |
|
93 + print("Install testrepository to run 'testr' command properly.") |
|
94 + |
|
95 + |
|
96 +try: |
|
97 + from testrepository import commands |
|
98 + have_testr = True |
|
99 + Testr = TestrReal |
|
100 +except ImportError: |
|
101 + have_testr = False |
|
102 + Testr = TestrFake |