Skip to content

Using tmpdir in session scoped fixture changes the fixture to be function scoped #659

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

Closed
pytestbot opened this issue Jan 15, 2015 · 2 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Torsten Landschoff (BitBucket: bluehorn, GitHub: bluehorn)


Running the attached tests gives

$ py.test -q --tb=short test_cached_mkdtemp.py
..
2 passed in 0.03 seconds

as expected, but doing the same using tmpdir I get

$ py.test -q --tb=short test_cached_tmpdir.py
.E
==================================== ERRORS ====================================
______________________ ERROR at setup of test_property_b _______________________
test_cached_tmpdir.py:21: in scenario_prototype
    return ScenarioPrototype(tmpdir.join("prototype"))
test_cached_tmpdir.py:40: in __init__
    assert ScenarioPrototype.instantiation_count <= 1
E   assert 2 <= 1
E    +  where 2 = ScenarioPrototype.instantiation_count
------------------------------- Captured stdout --------------------------------
Creating scenario prototype in /tmp/pytest-89/test_property_b0/prototype
1 passed, 1 error in 0.03 seconds

Tested with pytest 2.6.4 and pytest 2.5.1. I would have expected both to behave identically.


@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
@RonnyPfannschmidt
Copy link
Member

@Bluehorn is this still an issue with 2.7 and master?

@nicoddemus
Copy link
Member

This is what I get on master:

=================================== ERRORS ====================================
______________________ ERROR at setup of test_property_a ______________________
ScopeMismatch: You tried to access the 'function' scoped fixture 'tmpdir' with a 'session' scoped request object, involved factories
test_cached_tmpdir.py:23:  def scenario(tmpdir, scenario_prototype)
test_cached_tmpdir.py:14:  def scenario_prototype(tmpdir)
______________________ ERROR at setup of test_property_b ______________________
ScopeMismatch: You tried to access the 'function' scoped fixture 'tmpdir' with a 'session' scoped request object, involved factories
test_cached_tmpdir.py:23:  def scenario(tmpdir, scenario_prototype)
test_cached_tmpdir.py:14:  def scenario_prototype(tmpdir)
=========================== 2 error in 0.02 seconds ===========================

So I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

3 participants