How to allow python tests with same file/module names?

1,770 views
Skip to first unread message

Ximing Yu

unread,
Mar 30, 2015, 7:54:56 PM3/30/15
to pants...@googlegroups.com
I'm having a file structure like below:

- tests/python/project-a
  - module_a
    - test_xxx.py
    - module_b/module_c
      - test_xxx.py


And when I run `./pants test tests/python/project-a/module_a/::` I end up having the following error:

import file mismatch:
imported module 'test_territory' has this __file__ attribute:
  /Users/.../tests/python/project-a/module_a/test_xxx.py
which is not the same as the test file we want to collect:
  /Users/.../tests/python/project-a/module_a/module_b/module_c/test_xxx.py
HINT: remove __pycache__ / .pyc files and/or use a unique basename for your test file modules

I know I can just rename one of the test files.  But since I'm intending to migrate some existing codebase which used to be in multiple repos into one Pants-managed repo, it will tremendously simplify the process if Pants allow test files with same name.  Any way to achieve that?  Thanks.

John Sirois

unread,
Mar 30, 2015, 7:59:01 PM3/30/15
to Ximing Yu, pants-devel

On Mon, Mar 30, 2015 at 5:46 PM, Ximing Yu <ximi...@gmail.com> wrote:
and/or use a unique basename for your test file modules

This is not a pants limitation per-se but a py.test limitation (we use py.test to run your tests).
IE: add __init__.pys in your test tree to work around.

John Sirois

unread,
Mar 30, 2015, 8:22:02 PM3/30/15
to Yu, Ximing, pants-devel
I responded there.

On Mon, Mar 30, 2015 at 6:14 PM, Yu, Ximing <ximi...@gmail.com> wrote:
John, if I add __init__.pys into my test tree I'm running into issues reported in https://github.com/pantsbuild/pants/issues/1345.
--
Ximing

Yu, Ximing

unread,
Mar 30, 2015, 8:22:28 PM3/30/15
to John Sirois, pants-devel
John, if I add __init__.pys into my test tree I'm running into issues reported in https://github.com/pantsbuild/pants/issues/1345.
On Mon, Mar 30, 2015 at 4:59 PM, John Sirois <john....@gmail.com> wrote:



--
Ximing
Reply all
Reply to author
Forward
0 new messages