小编Pau*_*ldo的帖子

Moto 不适用于 python 单元测试 setUp() 调用

我正在使用 moto 和 Python 3.7 来模拟一些 S3 交互。如果所有模拟代码都包含在测试方法中,那么 moto 似乎可以正常工作。当我将一些初步代码移动到 时setUp(),测试失败了,好像setUp()从未运行过一样。

import unittest

import boto3
from moto import mock_s3

class BucketFacadeTests(unittest.TestCase):

    @mock_s3
    def setUp(self):
        print('setUp called')
        s3 = boto3.resource('s3', region_name='us-east-1')
        s3.create_bucket(Bucket='bucket')
        key = 'a/b/c/d.txt'
        object = s3.Object('bucket', key)
        object.put(Body='my dog has fleas')

    def do_test(self):
        s3 = boto3.resource('s3', region_name='us-east-1')
        the_object = s3.Object('bucket', 'a/b/c/d.txt')
        string_data = the_object.get()['Body'].read().decode('utf-8')
        self.assertEqual('my dog has fleas', string_data)

    @mock_s3
    def test_bucket_can_be_accessed_with_setup(self):
        self.do_test()

    @mock_s3
    def test_bucket_can_be_accessed_without_setup(self):
        # This does what setUp() should
        s3 = boto3.resource('s3', …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services boto3 moto

10
推荐指数
1
解决办法
2668
查看次数

git 替换失败:对象的替换深度太高

我正在尝试git replace并犯了一个错误。现在我已经无法回到正常的状态了。任何重要的 git 命令都会产生错误fatal: replace depth too high for object b769532341677b7c34b5adeb85a173daa0ced852git reset --hardgit checkout <another_branch>产生这个错误。

我不在乎结果replace,我只想恢复正常。我该怎么做呢?

git

8
推荐指数
1
解决办法
1469
查看次数

Grails 3集成测试中没有transactionManager错误

我创建了一个新的Grails 3.1.4角度项目以及一些域对象和控制器扩展RestfulController.我在下面创建了集成测试.当我跑步时,grails test-app -integration我得到了错误

java.lang.IllegalStateException: No transactionManager was specified. Using @Transactional or @Rollback requires a valid configured transaction manager. If you are running in a unit test ensure the test has been properly configured and that you run the test suite not an individual test method.
    at grails.transaction.GrailsTransactionTemplate.<init>(GrailsTransactionTemplate.groovy:60)
    at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.$tt__$spock_feature_0_0(BillingEntityRestControllerIntegrationSpec.groovy:29)
    at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.test all entities_closure2(BillingEntityRestControllerIntegrationSpec.groovy)
    at groovy.lang.Closure.call(Closure.java:426)
    at groovy.lang.Closure.call(Closure.java:442)
    at grails.transaction.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:70)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at grails.transaction.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:67)
    at com.waldoware.invoicer.BillingEntityRestControllerIntegrationSpec.test all entities(BillingEntityRestControllerIntegrationSpec.groovy)
Run Code Online (Sandbox Code Playgroud)

测试类:

package com.waldoware.invoicer

import grails.test.mixin.integration.Integration
import grails.transaction.*
import …
Run Code Online (Sandbox Code Playgroud)

grails unit-testing spock grails-3.0 grails-3.1

7
推荐指数
1
解决办法
2238
查看次数

避免在单元测试中运行顶层模块代码

我正在尝试对一些导入模块的 Python 3 代码进行单元测试。不幸的是,模块的编写方式,简单地导入它会产生令人不快的副作用,这对测试来说并不重要。我试图用unitest.mock.patch它来解决它,但运气不佳。

这是说明性示例的结构:

.
??? work
    ??? __init__.py
    ??? test_work.py
    ??? work.py
    ??? work_caller.py
Run Code Online (Sandbox Code Playgroud)

__init__.py 是一个空文件

工作.py

.
??? work
    ??? __init__.py
    ??? test_work.py
    ??? work.py
    ??? work_caller.py
Run Code Online (Sandbox Code Playgroud)

work_caller.py

import os


def work_on():
    path = os.getcwd()
    print(f"Working on {path}")
    return path

def unpleasant_side_effect():
    print("I am an unpleasant side effect of importing this module")

# Note that this is called simply by importing this file
unpleasant_side_effect()
Run Code Online (Sandbox Code Playgroud)

测试工作.py

from work.work import work_on

class WorkCaller:
    def call_work(self):
        # Do …
Run Code Online (Sandbox Code Playgroud)

python unit-testing monkeypatching

7
推荐指数
1
解决办法
382
查看次数

仅将 AWS Aurora Engine 版本指定为 Terraform 中的主版本号

我有一些创建 AWS Aurora RDS 集群的 Terraform 代码:

resource "aws_rds_cluster" "default" {
  provider                = aws.customer
  cluster_identifier      = "my_id"
  engine                  = "aurora-mysql"
  engine_version          = "5.7.mysql_aurora.2.03.2"
  database_name           = var.db_name
  port                    = var.db_port
  master_username         = var.db_master_username
  master_password         = random_password.sqlpassword.result
  backup_retention_period = 5
  preferred_backup_window = "07:00-09:00"
  skip_final_snapshot     = true
  db_subnet_group_name    = aws_db_subnet_group.default.name
  vpc_security_group_ids  = [aws_security_group.rds.id]
  deletion_protection     = true
}
Run Code Online (Sandbox Code Playgroud)

这段代码已经工作正常有一段时间了,直到最近因此terraform apply错误而失败Error: Failed to modify RDS Cluster (my_id): InvalidParameterCombination: Cannot upgrade aurora-mysql from 5.7.mysql_aurora.2.07.2 to 5.7.mysql_aurora.2.03.2

长话短说,AWS 在维护时段升级了次要版本号,并拒绝允许 Terraform 降级数据库。我同意 AWS 这样做,但我不想每次发生这种情况时都必须提交新的 Terraform …

amazon-web-services terraform amazon-aurora terraform-provider-aws

7
推荐指数
1
解决办法
3831
查看次数

Eclipse Organize Imports快捷方式在Mac上不起作用

我在macOS Sierra上使用Eclipse(STS版本3.9.0).我有一个全新的STS安装.组织导入(Cmd + Shift + O)是开箱即用的.我可以通过浏览菜单条目Source> Organize Imports来使用此功能,但键组合不起作用.

此外,快捷方式组合不会显示在菜单项旁边,而其他菜单项则显示快捷键组合.
缺少菜单快捷方式

如何通过按键获得此功能?

我见过这种情况发生在两台不同的机器上.

我通过绑定排序检查没有其他冲突的键绑定:

属性|  按键

java eclipse macos keyboard-shortcuts

1
推荐指数
1
解决办法
2998
查看次数