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

xfail condition should include `platform` module in namespace #3236

jaraco opened this Issue Feb 19, 2018 · 6 comments


None yet
5 participants

jaraco commented Feb 19, 2018

One can currently write:

@pytest.xfail("sys.platform == 'darwin'")

But not

@pytest.xfail("platform.platform() == 'Darwin'")

If one tries that, an error is raised:

Error evaluating 'xfail' expression
    platform.platform() == "Darwin"
NameError: name 'platform' is not defined

It seems reasonable to me the platform module should be exposed in the namespace for these conditional methods for the same reason sys is.

I searched but could not find an existing issue or even a definition of what these conditional expressions are guaranteed to support, so I hope this is not a duplicate report.


This comment has been minimized.


nicoddemus commented Feb 19, 2018

Definitely, thanks for the suggestion.


This comment has been minimized.


nicoddemus commented Feb 19, 2018

This is a great first contribution, cc @feuillemorte.


This comment has been minimized.


blueyed commented Feb 19, 2018

For what it's worth: I do not see the NameError when trying that (pytest

==================================== test session starts ====================================
platform linux -- Python 3.6.4, pytest-3.3.3.dev15+g794fb193, py-1.5.2, pluggy-0.6.0
Using --randomly-seed=1519069598
Django settings: X.settings (from environment variable)
rootdir: …/project/project, inifile: setup.cfg
plugins: xdist-1.22.0, travis-fold-1.3.0, testmon-0.9.9, repeat-0.4.1, randomly-1.2.2, profiling-1.2.11, mock-1.6.3, forked-0.2, django-3.1.2, cov-2.5.1, asyncio-0.8.0, annotate-1.0.1, celery-4.1.0, pdb-0.3.0.dev0
collected 0 items / 1 errors                                                                

================================== short test summary info ==================================
ERROR tests/
========================================== ERRORS ===========================================
_____________________________ ERROR collecting tests/ ______________________________
tests/ in <module>
    @pytest.xfail("platform.platform() == 'Darwin'")
E   _pytest.outcomes.XFailed: platform.platform() == 'Darwin'
!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!
================================== 1 error in 0.21 seconds ==================================

I wanted to try if @pytest.xfail("__import__('platform').platform() != 'Darwin'") could be used as a workaround, but the outcome is the same as above
for me.


This comment has been minimized.


nicoddemus commented Feb 19, 2018

Now that I think about it, perhaps it uses the global namespace of the module of the test?


This comment has been minimized.

svuki commented Feb 23, 2018

If I'm understanding correctly the problem isn't outcomes.xfail but the xfail mark which is talked about in the docs here.

If that's the case then the relevant code for what's available during evaluation of conditions is here:


Lines 110 to 114 in bedceaa

def _getglobals(self):
d = {'os': os, 'sys': sys, 'config': self.item.config}
if hasattr(self.item, 'obj'):
return d

So it's the global namespace of the module of the test plus os, sys, and item.config.


This comment has been minimized.


nicoddemus commented Feb 26, 2018

@svuki thanks for clarifying that! I believe we can just add platform to that initial directory in there then, I believe platform is as useful as sys.

nicoddemus added a commit that referenced this issue Feb 27, 2018

@nicoddemus nicoddemus closed this Feb 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment