小编Tim*_*nov的帖子

如何为 REST API 正确配置 Nginx 缓存?

案例:我有通过 HTTPS 的 REST API,我想在我的主机上配置基本的缓存代理服务来缓存 API 请求并像往常一样更快地获取相同的信息。

我的 Nginx 配置如下:

proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:10m max_size=10g
                 inactive=60m use_temp_path=off;
http {
    server {
        location /my_api/ {
            proxy_redirect off;
            proxy_buffering on;

            proxy_ignore_headers X-Accel-Expires;
            proxy_ignore_headers Expires;
            proxy_ignore_headers Cache-Control;

            proxy_cache my_cache;

            proxy_pass https://example.com/myapi/;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我正在比较 REST API 和我的本地代理服务的响应时间,并且 REST API 对远程服务的调用和对带有缓存的本地代理服务的响应时间是相同的,因此,这意味着缓存不会工作。另外,缓存目录是空的。

真实 API 的示例或请求(这不是真实情况):

    curl "https://example.com/myapi/?key=1"
Run Code Online (Sandbox Code Playgroud)

代理请求示例:

    curl "http://127.0.0.1:8080/myapi/?key=1"
Run Code Online (Sandbox Code Playgroud)

在 REST API 标头中我可以看到

cache-control: max-age=0, no-cache, no-store, must-revalidate
Run Code Online (Sandbox Code Playgroud)

Nginx 能以某种方式忽略它吗?

我应该在代理配置中更改哪些内容才能看到 REST API 的提升?我想知道这个问题是否与 HTTPS 流量有关?或者 REST API 的响应可能有一些 NoChaching 标头,或者响应的大小对于缓存来说太小?

caching nginx nginx-config

7
推荐指数
1
解决办法
8477
查看次数

PyTest不会运行任何测试

PyTest没有运行任何测试,也不清楚为什么.我试图使用--debug但没有得到任何有价值的信息.目前尚不清楚如何使用pytest调试此类问题(看起来像PyTest配置/ env变量/测试名称模式有些问题?)

测试文件示例:

$ cat test_sanity.py 
import pytest


@pytest.mark.sanity
def test_me():
    """ I'm a test. """

    assert True
Run Code Online (Sandbox Code Playgroud)

但是PyTest没有运行任何测试:

$ pytest
================================================== test session starts ===================================================
platform linux2 -- Python 2.7.12, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: /home/qawizard/pytest-hell, inifile:
plugins: xdist-1.15.0, timeout-1.2.0
collected 1 item s

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Exit: Done! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================== no tests ran in 0.13 seconds ==============================================
Run Code Online (Sandbox Code Playgroud)

为什么这样?

python pytest

6
推荐指数
1
解决办法
3130
查看次数

PyTest & Allure:Allure 报告中失败的屏幕截图

我正在尝试将屏幕截图附加到诱惑报告中,现在我正在使用以下代码:

@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    rep = outcome.get_result()
    setattr(item, "rep_" + rep.when, rep)
    return rep


@pytest.fixture(scope="function")
def web_browser(request):
    # Open browser:
    b = webdriver.PhantomJS()

    # Return browser instance to test case:
    yield b

    # Do teardown (this code will be executed after each test):

    if request.node.rep_call.failed:
        # Make the screen-shot if test failed:
        try:
            # Make screen-shot for Allure report:
            allure.attach(str(request.function.__name__),
                          b.get_screenshot_as_png(),
                          type=AttachmentType.PNG)
        except:
            pass # just ignore

    # Close browser window:
    b.quit()
Run Code Online (Sandbox Code Playgroud)

但它不起作用 - 当某些测试失败时,我在报告中看不到任何屏幕截图。 …

pytest selenium-webdriver allure

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