Why pytest always says ” ImportError: attempted relative import with no known parent package”
I found I must add __init__.py in test and projroot. __init__.py in src is not necessary. And pytest could run correctly in 3 folders: # parent folder of project root C:\>pytest projroot # project root C:\>cd projroot C:\projroot>pytest # test folder C:\projroot>cd test C:\projroot\test>pytest