Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lgbaldoni opened this issue Dec 10, 2019 · 4 comments · May be fixed by #113 or #129
Open

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

lgbaldoni opened this issue Dec 10, 2019 · 4 comments · May be fixed by #113 or #129

Comments

@lgbaldoni
Copy link

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
Copy link

mcepl commented Dec 13, 2019

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
Copy link

qha commented May 25, 2020

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

@lgbaldoni
Copy link
Author

@qha works for me

@qha
Copy link

qha commented May 26, 2020

Thank you for the confirmation!

@mondeja mondeja linked a pull request Aug 23, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants