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

Session recreated on tests that use pytest.parametrize #5

Closed
joac opened this issue Apr 22, 2016 · 1 comment
Closed

Session recreated on tests that use pytest.parametrize #5

joac opened this issue Apr 22, 2016 · 1 comment

Comments

@joac
Copy link
Contributor

joac commented Apr 22, 2016

As is reported on: pytest-dev/pytest#634
metafunc.parametrize overwrite scopes.
This produce a recreation of the entire session on tests that use parametrize.

This can be easily fixed using request.config.option.sql_url inside _sqlalchemy instead passing it as a fixture.

I'm working on a PR to fix this ASAP

This is my test case test_pytest.py:

from __future__ import print_function

import pytest

from pyramid_sqlalchemy import BaseObject
from sqlalchemy import Column, Integer


class Model(BaseObject):
    __tablename__ = 'models'
    id = Column(Integer, primary_key=True)


@pytest.mark.parametrize('n', xrange(3))
def test_standar_foo(n, sql_session):
    print('parameter foo', n)

and this is the result of running py.test test_pytest.py --sql-echo -s

============================= test session starts ==============================
platform linux2 -- Python 2.7.6, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /home/joac/other_repos/pyramid_sqlalchemy, inifile: setup.cfg
plugins: pyramid-sqlalchemy-1.5
collected 3 items

test_pytest.py 2016-04-22 11:13:40,064 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,064 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,064 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,064 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,065 INFO sqlalchemy.engine.base.Engine PRAGMA foreign_keys = ON
2016-04-22 11:13:40,065 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,065 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,065 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,066 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE models (
    id INTEGER NOT NULL, 
    PRIMARY KEY (id)
)


2016-04-22 11:13:40,066 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,066 INFO sqlalchemy.engine.base.Engine COMMIT
parameter foo 0
.2016-04-22 11:13:40,068 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,068 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,068 INFO sqlalchemy.engine.base.Engine 
DROP TABLE models
2016-04-22 11:13:40,068 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,068 INFO sqlalchemy.engine.base.Engine COMMIT
2016-04-22 11:13:40,070 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,070 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,070 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,070 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine PRAGMA foreign_keys = ON
2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE models (
    id INTEGER NOT NULL, 
    PRIMARY KEY (id)
)


2016-04-22 11:13:40,071 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,072 INFO sqlalchemy.engine.base.Engine COMMIT
parameter foo 1
.2016-04-22 11:13:40,073 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,073 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,074 INFO sqlalchemy.engine.base.Engine 
DROP TABLE models
2016-04-22 11:13:40,074 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,074 INFO sqlalchemy.engine.base.Engine COMMIT
2016-04-22 11:13:40,075 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS VARCHAR(60)) AS anon_1
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine PRAGMA foreign_keys = ON
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,076 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,077 INFO sqlalchemy.engine.base.Engine 
CREATE TABLE models (
    id INTEGER NOT NULL, 
    PRIMARY KEY (id)
)


2016-04-22 11:13:40,077 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,077 INFO sqlalchemy.engine.base.Engine COMMIT
parameter foo 2
.2016-04-22 11:13:40,078 INFO sqlalchemy.engine.base.Engine PRAGMA table_info("models")
2016-04-22 11:13:40,078 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,078 INFO sqlalchemy.engine.base.Engine 
DROP TABLE models
2016-04-22 11:13:40,078 INFO sqlalchemy.engine.base.Engine ()
2016-04-22 11:13:40,078 INFO sqlalchemy.engine.base.Engine COMMIT


=========================== 3 passed in 0.03 seconds ===========================u
@joac
Copy link
Contributor Author

joac commented Apr 22, 2016

@wichert here is my PR that fix this #6

wichert added a commit that referenced this issue Apr 28, 2016
Fix #5 issues with session recreated on parametrized tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant