one or more assertions failed

一、背景

     postgresql数据库执行insert into control_papers(id,num) values('88',NULL),报错误one or more assertions failed

二、解决

     此错误是因为num字段设置了不为NULL的约束,而此处插入了NULL,故报错。

三、断言

      断言就是一个针对数据表字段的约束。

1、断言的概念
  所谓断言就是一个谓词,它表达了我们希望数据库总能满足的一个条件。域约束和参照完整性约束是断言的特殊形式。


2、SQL-92中断言的定义形式
  create assertion <断言名> check <谓词>


3、断言的利弊
  ① 一方面能够保证数据库的一致性;
  ② 另一方面,检测和维护断言需要很大的开销,系统效率降的很低。一般不主张使用断言!

 

### Pytest Key Concepts and Features Pytest is a powerful tool that extends beyond simple unit testing into more complex areas such as integration, acceptance, and regression testing[^1]. The following sections outline some of the core concepts and features: #### Discovery Mechanism Pytest uses a discovery mechanism to automatically find tests within files named `test_*.py` or directories called `tests`. Test functions must start with `test_`, allowing pytest to identify them without explicit declarations. ```python def test_example(): assert True ``` #### Fixtures Fixtures provide setup services for tests. They allow sharing state across multiple tests using dependency injection principles. A fixture can be defined at different scopes (function, class, module, session). ```python import pytest @pytest.fixture def sample_data(): return {"key": "value"} def test_with_fixture(sample_data): assert isinstance(sample_data, dict) ``` #### Parametrization Parametrizing tests enables running the same test logic against various inputs efficiently. This feature helps ensure comprehensive coverage by varying input parameters easily. ```python import pytest @pytest.mark.parametrize( ("n", "expected"), [ (1, 2), (2, 3), (3, 4), ], ) def test_increment(n, expected): from mymodule import increment_by_one result = increment_by_one(n) assert result == expected ``` #### Plugins Support One significant advantage of pytest lies in its extensive plugin ecosystem. These plugins extend functionality, offering capabilities like HTML reports, remote execution support, etc., enhancing productivity significantly. #### Command-Line Interface The command-line interface offers flexibility through options controlling verbosity, selecting specific tests, generating reports among others. ```bash pytest --verbose -k "not slow" ``` #### Assertions Debugging When an assertion fails, pytest provides detailed explanations about why it failed, which simplifies debugging processes considerably compared to standard unittest frameworks. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fang·up·ad

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值