Repository: RasaHQ/rasa
Pull request: remove warning when running `rasa x --production`

**Proposed changes**:
- Move the warning raised for `rasa x` so that it does not warn for `rasa x --production` which does not start localmode.

**Status (please check what you already did)**:
- [x] added some tests for the functionality
- [x] updated the changelog (please check [changelog](https://github.com/RasaHQ/rasa/tree/main/changelog) for instructions)
- [x] reformat files using `black` (please check [Readme](https://github.com/RasaHQ/rasa#code-style) for instructions)


Problem statement:
Remove `UserWarning` that gets raised when running `rasa x` with rasa 3.0 once rasa-x adds support for 3.0
This is a wrap-up issue once rasa-x support for rasa 3.0 has been added.

**Definition of Done**:

*   [ ] `UserWarning` raised in `rasa/cli/x.py::rasa_x` is removed, as well as the accompanying unit test `test_rasa_x_raises_warning_above_version_3`

Hints from issue discussion:
Hello, Has this issue been resolved?
This issue isn't relevant in its original form anymore, since Rasa 3.0 dropped support for Rasa X localmode.

However, there is an exception that now needs to be handled: The command `rasa x --production`, which starts a Rasa Open Source Server (not Rasa X) should not throw this warning, since that form of the command is not deprecated.

Commit message: changelog

Patch to review:
diff --git a/changelog/10480.bugfix.md b/changelog/10480.bugfix.md
new file mode 100644
index 000000000000..20c39902fd43
--- /dev/null
+++ b/changelog/10480.bugfix.md
@@ -0,0 +1 @@
+Remove warning for Rasa X localmode not being supported when the `--production` flag is present.
diff --git a/rasa/cli/x.py b/rasa/cli/x.py
index 64f6c4035c4a..3881751f2e32 100644
--- a/rasa/cli/x.py
+++ b/rasa/cli/x.py
@@ -350,17 +350,15 @@ def rasa_x(args: argparse.Namespace) -> None:
 
     _configure_logging(args)
 
-    if version.parse(rasa.version.__version__) >= version.parse("3.0.0"):
+    if args.production:
+        run_in_production(args)
+    else:
         rasa.shared.utils.io.raise_warning(
             f"Your version of rasa '{rasa.version.__version__}' is currently "
             f"not supported by Rasa X. Running `rasa x` CLI command with rasa "
             f"version higher or equal to 3.0.0 will result in errors.",
             UserWarning,
         )
-
-    if args.production:
-        run_in_production(args)
-    else:
         run_locally(args)
 
 
diff --git a/tests/cli/test_rasa_x.py b/tests/cli/test_rasa_x.py
index 9981fbd87cdd..5bbf5131fa71 100644
--- a/tests/cli/test_rasa_x.py
+++ b/tests/cli/test_rasa_x.py
@@ -1,6 +1,7 @@
 import sys
 import argparse
 from pathlib import Path
+import warnings
 
 import pytest
 from typing import Callable, Dict
@@ -13,6 +14,7 @@
 from rasa.cli import x
 from rasa.utils.endpoints import EndpointConfig
 from rasa.core.utils import AvailableEndpoints
+import rasa.version
 
 
 def test_x_help(run: Callable[..., RunResult]):
@@ -163,22 +165,34 @@ async def test_pull_runtime_config_from_server():
         assert rasa.shared.utils.io.read_file(credentials_path) == credentials
 
 
-def test_rasa_x_raises_warning_above_version_3(
-    monkeypatch: MonkeyPatch, run: Callable[..., RunResult]
-):
+def test_rasa_x_raises_warning_above_version_3(monkeypatch: MonkeyPatch):
     def mock_run_locally(args):
         return None
 
     monkeypatch.setattr(x, "run_locally", mock_run_locally)
-    monkeypatch.setattr(rasa.version, "__version__", "3.0.0")
 
     args = argparse.Namespace(loglevel=None, log_file=None, production=None)
     with pytest.warns(
         UserWarning,
-        match="Your version of rasa '3.0.0' is currently not supported by Rasa X.",
+        match=f"Your version of rasa '{rasa.version.__version__}' is currently not supported by Rasa X.",
     ):
         x.rasa_x(args)
 
     monkeypatch.setattr(target=rasa.version, name="__version__", value="2.8.0")
     with pytest.warns(None):
         x.rasa_x(args)
+
+
+def test_rasa_x_does_not_raise_warning_above_version_3_with_production_flag(
+    monkeypatch: MonkeyPatch,
+):
+    def mock_run_in_production(args):
+        return None
+
+    monkeypatch.setattr(x, "run_in_production", mock_run_in_production)
+
+    args = argparse.Namespace(loglevel=None, log_file=None, production=True)
+
+    with warnings.catch_warnings():
+        warnings.simplefilter("error")
+        x.rasa_x(args)


Code review comments:
diff_hunk: @@ -163,22 +165,34 @@ async def test_pull_runtime_config_from_server():
         assert rasa.shared.utils.io.read_file(credentials_path) == credentials
 
 
-def test_rasa_x_raises_warning_above_version_3(
-    monkeypatch: MonkeyPatch, run: Callable[..., RunResult]
-):
+def test_rasa_x_raises_warning_above_version_3(monkeypatch: MonkeyPatch):
     def mock_run_locally(args):
         return None
 
     monkeypatch.setattr(x, "run_locally", mock_run_locally)
-    monkeypatch.setattr(rasa.version, "__version__", "3.0.0")
 
     args = argparse.Namespace(loglevel=None, log_file=None, production=None)
     with pytest.warns(
         UserWarning,
-        match="Your version of rasa '3.0.0' is currently not supported by Rasa X.",
+        match=f"Your version of rasa '{rasa.version.__version__}' is currently not supported by Rasa X.",
     ):
         x.rasa_x(args)
 
     monkeypatch.setattr(target=rasa.version, name="__version__", value="2.8.0")
     with pytest.warns(None):
         x.rasa_x(args)
+
+
+def test_rasa_x_does_not_raise_warning_above_version_3_with_production_flag(
+    monkeypatch: MonkeyPatch,
+):
+    def mock_run_in_production(args):
+        return None
+
+    monkeypatch.setattr(x, "run_in_production", mock_run_in_production)
+
+    args = argparse.Namespace(loglevel=None, log_file=None, production=True)
+
+    with warnings.catch_warnings():
path: tests/cli/test_rasa_x.py
text: @user1:
I think you either may need to assert there are no `UserWarnings` raised, or use `with pytest.warns(None)` as context manager here.