Issues (109)

tests/conftest.py (3 issues)

1
from __future__ import print_function
2
3
import itertools
4
from datetime import datetime, timedelta
5
6
import faker
7
import pytest
8
from sqlalchemy import create_engine
9
from sqlalchemy.orm import sessionmaker
10
11
from .models import Address, Base, User
12
13
14
def populate(session):
0 ignored issues
show
Comprehensibility Bug introduced by
session is re-defining a name which is already available in the outer-scope (previously defined on line 39).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
15
    """Create 3 adresses and 50 users."""
16
    users = []
17
    f = faker.Faker(seed=1)
18
    addresses = [Address(description=d) for d in ['Street', 'Avenue', 'Road']]
19
    session.add_all(addresses)
20
21
    for i, addr in zip(range(0, 50), itertools.cycle(addresses)):
22
        user = User(
23
            name=f.name(),
24
            address=addr,
25
            birthday=datetime(1970, 1, 2) + timedelta(days=10 * i))
26
        users.append(user)
27
28
    session.add_all(users)
29
    session.commit()
30
31
32
@pytest.fixture(scope="session")
33
def engine():
34
    print("TestCase: Using sqlite database")
35
    return create_engine('sqlite:///', echo=False)
36
37
38
@pytest.fixture(scope="session")
39
def session(engine):
0 ignored issues
show
Comprehensibility Bug introduced by
engine is re-defining a name which is already available in the outer-scope (previously defined on line 33).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
40
    sessionmaker_ = sessionmaker(bind=engine)
41
    session = sessionmaker_()
0 ignored issues
show
Comprehensibility Bug introduced by
session is re-defining a name which is already available in the outer-scope (previously defined on line 39).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
42
    Base.metadata.create_all(engine)
43
    populate(session)
44
45
    yield session
46
47
    session.close()
48