So I attempted to to create a dynamodb table to run my tests with a pytest fixture like so:
@pytest.fixture
def db_resource():
db_resource = boto3.resource('dynamodb')
table = db_resource.create_table(
...
return db_resource
Then I passed it into my test like so:
@mock_dynamodb2
def test_my_code(db_resource):
other_func(db_resource)
This throws an error saying the table I just created does not exist (this is the first time I've tried doing it this way). However if I change it to a function that generates the table it works fine.
@mock_dynamodb2
def _create_table():
db_resource = boto3.resource('dynamodb')
table = db_resource.create_table(
...
return db_resource
and call it in my unit test function...
@mock_dynamodb2
def test_my_code():
db_resource = _create_table()
other_func(db_resource)
This works fine. What am I missing?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…