简体   繁体   English

谁知道nosetest的-m,-i和-e如何工作?

[英]Anyone know how nosetest's -m, -i and -e work?

I am trying to get nosetests to identify my tests but it is not running any of my tests properly. 我试图通过鼻子测试来识别我的测试,但它没有正确运行我的任何测试。

I have the following file structure 我有以下文件结构

Project
    +----Foo/
          +----__init__.py
          +----bar.py
    +----test/
          +----__init__.py
          +----unit/
                +----__init__.py
                +----bar_test.py
          +----functional/
                +----__init__.py
                +----foo_test.py

Within bar_test.py 在bar_test.py内

class BarTest(unittest.TestCase):
     def bar_1_test():
         ...

Within foo_test.py 在foo_test.py中

class FooFTest.py
     def foo_1_test():
         ...

Using -m, -i, -e options of nosetests 使用-m,-i,-e nosetests选项

  • What is the regex I need to run only unit tests (under unit/, tests in class BarTest) 我需要运行单元测试的正则表达式是什么(在单元/下,BarTest类中的测试)
  • What is the regex I need run only functional tests (under functional/, tests in class FooFTest) 什么是我需要的正则表达式只运行功能测试(在函数/,在类FooFTest中的测试)

I've tried various combinations and can't seem to get nosetests to do what I want consistently 我已经尝试了各种组合,似乎无法通过鼻子测试来做我想要的一贯

The easiest way to run only the tests under Project/test/unit is to use --where . 仅在Project/test/unit下运行测试的最简单方法是使用--where For example: 例如:

nosetests --where=Project/test/unit

Then use --match ( -m ) or --exclude ( -e ) to refine the list, if needed. 然后使用--match-m )或--exclude-e )来细化列表(如果需要)。

If you still want to use the regex selectors, you can probably do it like this (not tested): 如果您仍想使用正则表达式选择器,您可以这样做(未经测试):

nosetests --match='^Foo[\b_\./-])[Tt]est'

Executing this script from the Project directory would run all tests that start with "Foo" and end in "[Tt]est". Project目录执行此脚本将运行以“Foo”开头并以“[Tt] \\ test”结尾的所有测试。

As a general rule, you probably want to use either --match or --exclude , but not both. 作为一般规则,您可能希望使用--match--exclude ,但不能同时使用两者。 These parameters both specify the pattern of the function names to match. 这些参数都指定要匹配的函数名称的模式。 You can refine either one by using --ignore-files which, naturally, allows you to ignore whole files. 您可以使用--ignore-files来优化任何一个--ignore-files ,这当然可以让您忽略整个文件。

Given your directory structure, you can easily run segments of the tests using the --exclude option. 根据您的目录结构,您可以使用--exclude选项轻松运行测试的各个部分。

Run all tests: 运行所有测试:

nosetests Project

Run unit tests: 运行单元测试:

nosetests Project -e functional

Run functional tests: 运行功能测试:

nosetests Project -e unit

If you have more complex test execution needs, I'd recommend marking the tests and using the attrib package . 如果您有更复杂的测试执行需求,我建议标记测试并使用attrib包

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果有人有使用 Nvidia Jetbot 的经验,你知道如何更改 gstreamer 管道以使用网络摄像头吗? 我正在使用 c170 罗技 - If anyone has experience with the Nvidia Jetbot, do you know how to change the gstreamer pipeline to work with a webcam? I'm using a c170 Logitech 有人知道我为什么要得到“退出代码为0的进程完成”吗? - Anyone know why I'm getting a “Process finished with exit code 0”? 我收到一个导入错误,有人知道解决方案吗? - I'm getting an import error, does anyone know the solution? 如何使用GAE和Nosetest模拟用户? - How do I mock users with GAE and Nosetest? 我正在尝试使用 Flask 构建一个 Web 应用程序,但是我对 CSS 所做的更改不再反映在它上面。 有谁知道如何解决这一问题? - I'm trying to build a web app using flask, but changes I make to the CSS no longer reflect on it. Does anyone know how to fix this? 有谁知道如何使这项工作适用于面向对象的编程? - Does anyone know how to make this work it is for object orientated programming? 如何禁用nosetest插件 - how to disable a nosetest plugin 导入 flask 后出现问题,有人知道怎么回事吗? - I'm having an issue after I imported flask, anyone know whats up? 我正在尝试将tradingview脚本转换为python。 有人知道[]运算符的含义吗? - I'm trying to convert tradingview script to python. Does anyone know the meaning of [ ] operator? 有谁知道我可以把它变成一个循环吗? - Does anyone know how i can put this into a loop?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM