小编twi*_*ity的帖子

TravisCI PHPUnit致命错误 - 调用未定义的方法PHPUnit_Util_Configuration :: getTestdoxGroupConfiguration()

PHPUnit_Util_Configuration::getTestdoxGroupConfiguration()即使PHPUnit在本地运行没有问题,我的TravisCI构建也因为致命的错误引用而失败.我已经验证了TravisCI上的Composer正在安装与我在本地安装的相同版本的PHPUnit.

我注意到最近的一个补丁专门引用了testdox组配置,但我无法弄清楚为什么这个改变可能会破坏TravisCI中的PHPUnit而不是我的本地版本.

这是TravisCI的作曲家:

- Installing phpunit/phpunit (5.7.6) Downloading: 100%
Run Code Online (Sandbox Code Playgroud)

这是来自TravisCI的致命错误和堆栈跟踪:

PHP Fatal error:  Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in /home/travis/build/twistofreality/dilmun/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 1042
PHP Stack trace:
PHP   1. {main}() /home/travis/.phpenv/versions/5.6.5/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /home/travis/.phpenv/versions/5.6.5/bin/phpunit:722
PHP   3. PHPUnit_TextUI_Command->run() phar:///home/travis/.phpenv/versions/5.6.5/bin/phpunit/phpunit/TextUI/Command.php:104
PHP   4. PHPUnit_TextUI_TestRunner->doRun() phar:///home/travis/.phpenv/versions/5.6.5/bin/phpunit/phpunit/TextUI/Command.php:152
PHP   5. PHPUnit_TextUI_TestRunner->handleConfiguration() /home/travis/build/twistofreality/dilmun/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:163
Run Code Online (Sandbox Code Playgroud)

php phpunit travis-ci

5
推荐指数
1
解决办法
1424
查看次数

测试 Django REST Framework 时,为什么无法使用 APIClient.credentials() 使用令牌进行身份验证?

我正在针对基本 API 编写功能(而非单元)测试,如下所示:

from decouple import config
from rest_framework.test import APIClient, APITestCase


class ObjectAPIResponseTest(APITestCase):
    base_url = 'http://localhost:8000/api/objects/'
    token = config('LOCAL_API_TOKEN') # token stored in local .env file
    authenticated_client = APIClient()

    def setUp(self):
        self.authenticated_client.credentials(HTTP_AUTHORIZATION='Token ' + self.token)

    def test_list_object_reaches_api(self):
        real_response = self.authenticated_client.get(self.base_url)

        self.assertEqual(real_response.status_code, 200)
        self.assertEqual(real_response.headers['content-type'], 'application/json')
Run Code Online (Sandbox Code Playgroud)

测试失败:AssertionError: 401 != 200

使用curl成功测试请求后,我决定尝试requests使用Authorization标头加载,而不是使用Django REST Framework的APIClient

import requests

from decouple import config
from rest_framework.test import APIClient, APITestCase


class ObjectAPIResponseTest(APITestCase):
    base_url = 'http://localhost:8000/api/objects/'
    token = config('LOCAL_API_TOKEN') # token …
Run Code Online (Sandbox Code Playgroud)

python django functional-testing django-testing django-rest-framework

5
推荐指数
1
解决办法
3392
查看次数

为 React 应用程序运行 npm run build 时是否可以禁用 ESLint?

我有一个使用 Create React App 启动的应用程序,因此npm run build运行react-scripts build. 我最近安装了prettier,因此.eslintrc.json在项目根目录中添加了一个文件来加载插件prettiernpm run build在本地按预期工作,但是,当将应用程序部署到 Heroku 时,npm run build尝试运行 ESLint 并失败,因为插件devDependencies不是dependencies.

Failed to load plugin 'prettier' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-prettier'
Run Code Online (Sandbox Code Playgroud)

从之前与类似问题的争论中,我知道我可以NPM_CONFIG_PRODUCTION=false在 Heroku 中进行设置,以便它能够安装devDependencies,这实际上确实解决了部署问题。尽管如此,我很想知道是否有另一种不需要设置的解决方案NPM_CONFIG_PRODUCTION=false

在这种情况下是否可以npm run build完全阻止运行 ESLint 或阻止它尝试访问 中指定的插件.eslintrc.json?我承认添加.eslintrc.json.gitignore一种解决方案,但我希望在我的存储库中添加 ESLint 配置。

heroku npm eslint react-scripts create-react-app

5
推荐指数
1
解决办法
1213
查看次数