Python unit test layout

已回答

I'm trying to figure out the right layout for my unit tests so that I can run the same tests either in the IDE, or at the command line using standard Python commands.  My unit tests are written using the 'unittest' package, and I have a 'setup.py' that sets the source directory:

package_dir={'': 'src'},
packages=find_packages('src'),

I want to have all my package code in a 'src/' directory, and all my tests in a 'test/' directory, because I don't like having them commingled.

Right now what's tripping me up is that if I want to reference a package in the test files, I need to use 'test.package_name' when running from the command line, but just 'package_name' when running from IntelliJ, because IntelliJ does some some adjusting of 'sys.path' apparently.

What's a good way to have this all working well together, and then what command-line invocation ('nosetests', 'python setup.py test', or something else?) should I use?

I'm using IntelliJ IDEA CE 2016.3 with the Python plugin, and Python 3.6.

0

Can you give a try with the 2017.1 EAP release? We rewrote our test runners to bring them closer to the behavior you get when running from the command line.

0

I just downloaded 2017.1 EAP Build #IC-171.3780.15 and tried it again.  I still get the same behavior in IntelliJ where I need to *not* have the prefix 'test.' on package names.  I also double-checked that the working directory for the configuration is the top-level root of my project, not the 'test/' subdirectory.

0

Still looking for a workaround here.  Any hints on how to write a test that's compatible with something standard like `python setup.py test` on the command line?  Developers need to run tests in the IDE and our continuous build systems need to run them without it.

0

请先登录再写评论。