alex-rudakov / sphinx-argparse

Sphinx extension that automatically document argparse commands and options
MIT License
49 stars 40 forks source link

Some tests fail when py.test has a different name #121

Open lgbaldoni opened 4 years ago

lgbaldoni commented 4 years ago

Trying to package sphinx-argparse for openSUSE Tumbleweed and I've stumbled into a small problem.

To invoke the test we use a macro that cycles through the various python incarnations (2, 3 and pypy) and consequently each py.test executable comes with a different suffix. Unfortunately it looks like that test/test_parser.py has a hardcoded py.test name and takes exception to things being otherwise.

Do you see a way around this?

Regards

mcepl commented 4 years ago

OK, so this is rather awful hack how to deal with the problem:

--- a/test/test_parser.py
+++ b/test/test_parser.py
@@ -1,4 +1,8 @@
 import argparse
+import os
+import sys
+print("sys.path = {}".format(sys.path))
+
 from sphinxarg.parser import parse_parser, parser_navigate

@@ -129,6 +133,8 @@ def test_parse_description():

 def test_parse_nested():
+    pytest_name = os.environ['PYTEST_NAME'] if 'PYTEST_NAME' in os.environ \
+            else 'py.test'
     parser = argparse.ArgumentParser()
     parser.add_argument('foo', default=False, help='foo help')
     parser.add_argument('bar', default=False)
@@ -157,8 +163,8 @@ def test_parse_nested():
         {
             'name': 'install',
             'help': 'install help',
-            'usage': 'usage: py.test install [-h] [--upgrade] ref',
-            'bare_usage': 'py.test install [-h] [--upgrade] ref',
+            'usage': 'usage: {} install [-h] [--upgrade] ref'.format(pytest_name),
+            'bare_usage': '{} install [-h] [--upgrade] ref'.format(pytest_name),
             'action_groups': [
                 {
                     'title': 'Positional Arguments',
@@ -188,6 +194,8 @@ def test_parse_nested():

 def test_parse_nested_traversal():
+    pytest_name = os.environ['PYTEST_NAME'] if 'PYTEST_NAME' in os.environ \
+            else 'py.test'
     parser = argparse.ArgumentParser()

     subparsers1 = parser.add_subparsers()
@@ -223,8 +231,8 @@ def test_parse_nested_traversal():
         {
             'name': 'level3',
             'help': '',
-            'usage': 'usage: py.test level1 level2 level3 [-h] foo bar',
-            'bare_usage': 'py.test level1 level2 level3 [-h] foo bar',
+            'usage': 'usage: {} level1 level2 level3 [-h] foo bar'.format(pytest_name),
+            'bare_usage': '{} level1 level2 level3 [-h] foo bar'.format(pytest_name),
             'action_groups': [
                 {
                     'title': 'Positional Arguments',

(and of course you have set environmental variable PYTEST_NAME).

qha commented 4 years ago

I made a less awful fix in d7a8384f1d4a0a3074a803fc6429481a918e4780 (part of #113), could you test it and see if it solves the problem for you too?

lgbaldoni commented 4 years ago

@qha works for me

qha commented 4 years ago

Thank you for the confirmation!