1

Test file code for my fastapi app. Using Mas Os

from fastapi.testclient import TestClient
import json

import os 
import sys



sys.append.path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from main import app

client = TestClient(app)



# email already exists
def test_createAccount_existing_User():
    input_data = {"first_name":"first", "last_name":"last", "email":"user@example2.com", "password":"1234"}
    response = client.post('/account/', json.dump(input_data))
    assert response.status_code ==  400

Error that I am getting:

ERROR test_userRoute.py - AttributeError: module 'sys' has no attribute 'append'

When I am running pytest -v, showing error in the terminal.

Somnath Paul
  • 19
  • 1
  • 4
  • perhaps you meant `sys.path.append`? – ti7 May 15 '22 at 08:21
  • Your operating system is irrelevant. The *sys* module has no *append* attribute just as the error message indicates. What are you hoping to achieve with that line of code? – DarkKnight May 15 '22 at 08:21
  • You can explore the methods on some object with [`dir()`](https://docs.python.org/3/library/functions.html#dir) – ti7 May 15 '22 at 08:23
  • Does this answer your question? [Python import error while importing main module in conftest for Pytest framework](https://stackoverflow.com/questions/71079874/python-importerror-while-import-main-module-in-conftest-for-pytest-framework) – Chris May 15 '22 at 08:25

1 Answers1

2

To append to the path variable, use the syntax:

sys.path.append

You have these out of order.

sys.path is a list of search paths - append is just a built in method of list.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54