Navigation Menu

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

xfail condition should include platform module in namespace #3236

Closed
jaraco opened this issue Feb 19, 2018 · 6 comments
Closed

xfail condition should include platform module in namespace #3236

jaraco opened this issue Feb 19, 2018 · 6 comments
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic topic: marks related to marks, either the general marks or builtin type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@jaraco
Copy link
Contributor

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.

@RonnyPfannschmidt RonnyPfannschmidt added type: enhancement new feature or API change, should be merged into features branch status: help wanted developers would like help from experts on this topic type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature type: docs documentation improvement, missing or needing clarification topic: marks related to marks, either the general marks or builtin labels Feb 19, 2018
@nicoddemus
Copy link
Member

Definitely, thanks for the suggestion.

@nicoddemus nicoddemus added the good first issue easy issue that is friendly to new contributor label Feb 19, 2018
@nicoddemus
Copy link
Member

This is a great first contribution, cc @feuillemorte.

@blueyed
Copy link
Contributor

blueyed commented Feb 19, 2018

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

==================================== 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/test_t.py
========================================== ERRORS ===========================================
_____________________________ ERROR collecting tests/test_t.py ______________________________
tests/test_t.py:4: 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.

@nicoddemus
Copy link
Member

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

@svuki
Copy link

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:

pytest/_pytest/skipping.py

Lines 110 to 114 in bedceaa

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

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

@nicoddemus
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor status: help wanted developers would like help from experts on this topic topic: marks related to marks, either the general marks or builtin type: docs documentation improvement, missing or needing clarification type: enhancement new feature or API change, should be merged into features branch type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

5 participants