Skip to content

Coerce pytest args to str to fix assertion error in pytest#2512

Merged
eteq merged 2 commits into
astropy:masterfrom
eteq:fix-test-helper-unicode-error
May 19, 2014
Merged

Coerce pytest args to str to fix assertion error in pytest#2512
eteq merged 2 commits into
astropy:masterfrom
eteq:fix-test-helper-unicode-error

Conversation

@eteq

@eteq eteq commented May 17, 2014

Copy link
Copy Markdown
Member

This fixes a problem I encountered when running the tests with -t on an rst file. E.g., python setup.py test -t coordinates/index.rst That should run the doctests for just that file, but instead, it yields the cryptic traceback I've included at the bottom of this message. I traced the cause to a line deep in the bowels of pytest that does isinstance(arg, str), which fails for unicode arguments. So this PR just forces the arguments passed into pytest for setting plugins to be str.

running build_scripts
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "astropy/__init__.py", line 196, in test
    skip_docs=skip_docs)
  File "astropy/tests/helper.py", line 259, in run_tests
    result = pytest.main(args=all_args, plugins=plugins)
  File "_pytest.config", line 18, in main
  File "_pytest.config", line 62, in _prepareconfig
  File "_pytest.core", line 376, in __call__
  File "_pytest.core", line 387, in _docall
  File "_pytest.core", line 288, in execute
  File "_pytest.helpconfig", line 25, in pytest_cmdline_parse
  File "_pytest.core", line 288, in execute
  File "_pytest.config", line 617, in pytest_cmdline_parse
  File "_pytest.config", line 710, in parse
  File "_pytest.config", line 686, in _preparse
  File "_pytest.core", line 185, in consider_preparse
  File "_pytest.core", line 195, in consider_pluginarg
  File "_pytest.core", line 210, in import_plugin
AssertionError

@eteq eteq added this to the v0.4.0 milestone May 17, 2014
@mdboom

mdboom commented May 19, 2014

Copy link
Copy Markdown
Contributor

It appears we discovered a similar bug on Python < 2.7.3 at one point, because we already have this hack a few lines above:

        if sys.version_info < (2, 7, 3):
            all_args = [x.encode('utf-8') for x in all_args]

Maybe just do this for all versions of Python 2?

@eteq

eteq commented May 19, 2014

Copy link
Copy Markdown
Member Author

Good point, @mdboom - didn't notice that! That seems to do the trick.

@mdboom

mdboom commented May 19, 2014

Copy link
Copy Markdown
Contributor

Ok. 👍 for me once Travis has digested it.

@eteq

eteq commented May 19, 2014

Copy link
Copy Markdown
Member Author

Travis passed, so I'll merge now.

eteq added a commit that referenced this pull request May 19, 2014
Coerce pytest args to str to fix assertion error in pytest in all py2.x
@eteq eteq merged commit c4a8390 into astropy:master May 19, 2014
@eteq eteq deleted the fix-test-helper-unicode-error branch May 19, 2014 20:11
@eteq eteq mentioned this pull request May 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants