File tree 5 files changed +30
-17
lines changed
5 files changed +30
-17
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ Christian Tismer
63
63
Christoph Buelter
64
64
Christopher Dignam
65
65
Christopher Gilling
66
+ Claire Cecil
66
67
Claudio Madotto
67
68
CrazyMerlyn
68
69
Cyrus Maden
Original file line number Diff line number Diff line change
1
+ `pytest --version ` now displays just the pytest version, while `pytest --version --version ` displays more verbose information including plugins.
Original file line number Diff line number Diff line change @@ -41,8 +41,11 @@ def pytest_addoption(parser):
41
41
group .addoption (
42
42
"--version" ,
43
43
"-V" ,
44
- action = "store_true" ,
45
- help = "display pytest version and information about plugins." ,
44
+ action = "count" ,
45
+ default = 0 ,
46
+ dest = "version" ,
47
+ help = "display pytest version and information about plugins."
48
+ "When given twice, also display information about plugins." ,
46
49
)
47
50
group ._addoption (
48
51
"-h" ,
@@ -116,19 +119,22 @@ def unset_tracing():
116
119
117
120
118
121
def showversion (config ):
119
- sys .stderr .write (
120
- "This is pytest version {}, imported from {}\n " .format (
121
- pytest .__version__ , pytest .__file__
122
+ if config .option .version > 1 :
123
+ sys .stderr .write (
124
+ "This is pytest version {}, imported from {}\n " .format (
125
+ pytest .__version__ , pytest .__file__
126
+ )
122
127
)
123
- )
124
- plugininfo = getpluginversioninfo (config )
125
- if plugininfo :
126
- for line in plugininfo :
127
- sys .stderr .write (line + "\n " )
128
+ plugininfo = getpluginversioninfo (config )
129
+ if plugininfo :
130
+ for line in plugininfo :
131
+ sys .stderr .write (line + "\n " )
132
+ else :
133
+ sys .stderr .write ("pytest {}\n " .format (pytest .__version__ ))
128
134
129
135
130
136
def pytest_cmdline_main (config ):
131
- if config .option .version :
137
+ if config .option .version > 0 :
132
138
showversion (config )
133
139
return 0
134
140
elif config .option .help :
Original file line number Diff line number Diff line change @@ -1243,9 +1243,7 @@ def pytest_addoption(parser):
1243
1243
assert result .ret == ExitCode .USAGE_ERROR
1244
1244
1245
1245
result = testdir .runpytest ("--version" )
1246
- result .stderr .fnmatch_lines (
1247
- ["*pytest*{}*imported from*" .format (pytest .__version__ )]
1248
- )
1246
+ result .stderr .fnmatch_lines (["pytest {}" .format (pytest .__version__ )])
1249
1247
assert result .ret == ExitCode .USAGE_ERROR
1250
1248
1251
1249
Original file line number Diff line number Diff line change 2
2
from _pytest .config import ExitCode
3
3
4
4
5
- def test_version (testdir , pytestconfig ):
5
+ def test_version_verbose (testdir , pytestconfig ):
6
6
testdir .monkeypatch .delenv ("PYTEST_DISABLE_PLUGIN_AUTOLOAD" )
7
- result = testdir .runpytest ("--version" )
7
+ result = testdir .runpytest ("--version" , "--version" )
8
8
assert result .ret == 0
9
- # p = py.path.local(py.__file__).dirpath()
10
9
result .stderr .fnmatch_lines (
11
10
["*pytest*{}*imported from*" .format (pytest .__version__ )]
12
11
)
13
12
if pytestconfig .pluginmanager .list_plugin_distinfo ():
14
13
result .stderr .fnmatch_lines (["*setuptools registered plugins:" , "*at*" ])
15
14
16
15
16
+ def test_version_less_verbose (testdir , pytestconfig ):
17
+ testdir .monkeypatch .delenv ("PYTEST_DISABLE_PLUGIN_AUTOLOAD" )
18
+ result = testdir .runpytest ("--version" )
19
+ assert result .ret == 0
20
+ # p = py.path.local(py.__file__).dirpath()
21
+ result .stderr .fnmatch_lines (["pytest {}" .format (pytest .__version__ )])
22
+
23
+
17
24
def test_help (testdir ):
18
25
result = testdir .runpytest ("--help" )
19
26
assert result .ret == 0
You can’t perform that action at this time.
0 commit comments