Trying to test Flask endpoint. AttributeError: 'PosixPath' object has no attribute 'lstrip'

Trying to test Flask endpoint. AttributeError: 'PosixPath' object has no attribute 'lstrip'

我正在尝试使用 pytest 测试我的 Flask API,但我正在为这个错误而苦苦挣扎:AttributeError: 'PosixPath' object has no attribute 'lstrip'。当我向 /authentication/users 发出 post 请求时,它会被引发。当我使用 Postman 并且我的用户模型中的 unit tests 也工作时,端点工作正常(他们不使用 client)。这是我的代码:

# conftest.py

# ... imports here ...

@pytest.fixture
def client():
    app.config.from_object(TestSettings)
    with app.test_client() as client:
        with app.app_context():
            # starts connection with tests db
            db = MongoEngine(app)

        yield client  # Do the tests

        with app.app_context():
            # drop db after tests
            db.connection.drop_database('test')

我的测试使用client

# integrations/test_auth_endpoints.py
def test_create_user(client):
    """
    GIVEN the /authentication/users endpoint
    WHEN a POST request is made
    THEN check the status code, message and data of response
    """
    usr_data = {
        "nome": "ana",
        "cpf": "12345678913",
        "email": "ana@gmail.com",
        "password": "my-secret.@"
    }
    req = client.post('/authentication/users', data=usr_data)  # <-- AttributeError here
    assert req.status == 201

所以我做错了什么?

经过几个小时的调试。我弄清楚我做错了什么。 在我的设置中我设置了

APPLICATION_ROOT = Path(__file__).parent.parent

我错误地认为 APPLICATION_ROOT 是项目根并且它返回一个 PositionPath 对象。