English 中文(简体)
找出错误 抗药性
原标题:Getting error ImportMismatchError while running py.test

当我在当地测试其工作罚款时,但在制造cker子并在集装箱内运行之后,我会发现错误。

    /usr/local/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules
    return self._path2confmods[path]
E   KeyError: local( /apis/db/tests )

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest
    return self._conftestpath2mod[conftestpath]
E   KeyError: local( /apis/db/tests/conftest.py )

During handling of the above exception, another exception occurred:
/usr/local/lib/python3.5/site-packages/_pytest/config.py:362: in _importconftest
    mod = conftestpath.pyimport()
/usr/local/lib/python3.5/site-packages/py/_path/local.py:680: in pyimport
    raise self.ImportMismatchError(modname, modfile, self)

_pytest.config.ConftestImportFailure: ImportMismatchError( conftest ,  /projects/my_project/db/tests/conftest.py , local( /apis/db/tests/conftest.py ))

/apis - its the WORKDIR in Dockerfile.

问题回答

我通过删除所有pycache__加以确定。 在测试/目录中,问题在于,在测试使用我的当地机器道路而不是在码头集装箱内的道路时,我正在制造cker形,照亮了我的pycache__文档。

结论: http://www.pycpycache_文档,然后制作一个cker照图像。

I am using Python 3.6. In my case, I was getting ImportMismatchError in modules with the same name under different packages, e.g., A/B/main.py and C/D/main.py. Python 3 does not require __init__.py file in source folders, but adding __init__.py under A/B and C/D solved the issue.

您可以确定环境变量PY_IGNORE_IMPORTMISMATCH=1,以绕过这一频率。 对于像在码头集装箱内外进行试验这样的简单情况,应当予以罚款。

Delete all the .pyc files. You can do this by find . -name *.pyc -delete

Found __pycache__ files in coverage/fullcoverage/ which are hidden in jupyter notebook etc.

简单地说,与文件夹对应,使用<代码>rm -r __pyache__/。 这将照顾你们的考验。

In my case I was setting PYTHONPATH manually to the root of my repo. Inside of this I have a worktrees/ folder, which contains worktrees, each of which contain a python package. Since I told python to look for packages at the root of my repo, it would consider all packages under worktrees/ as well, thus leading to the import error. I resolved by flattening this nested structure.

如果您从名录/ROOT<>/strong>上运行,则确保FILE>下的某些地方。 如果是<>ELSEWHERE,则测试可尝试从ELSEWHERE上装载原始物并报告 ImportMismatchError。 这是我案件的原因。 http://strong>FILE,ROOT 确定了问题。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...