Repository: ionelmc/pytest-benchmark (language: python)

Issue:
--benchmark-disable still saves json files
Hi, I just upgraded from 3.2.3 to 3.4.1 (more or less by accident) and noticed that benchmark now saves json files if `--benchmark-disable`  is given together with `--benchmark-autosave`

(I use these flags in pytest.ini so I can just give `--benchmark-enable` and don't need to give autosave as well. Maybe I should not do that, I don't know.)

I think the previous behaviour was to issue a warning.

There are a couple of  problems I see with this:

1.) I get separate json files for each process I run with pytest-xdist
2.) Those json files contain no actual benchmark information
3.) This throws pytest-watch run with e.g. `--spool 1000 -- --testmon --testmon-forceselect` which will interrupt itself every time the json dump is written. (Of course `--ignore=.benchmarks` helps against that.)
4.) Those json files clutter the checkout.

My personal opinion is that saving benchmark data makes no sense if no actual benchmarks were run, so I'm happier with the warning in that case.

Any opinion or advice is appreciated here. I'm considering either downgrading, or changing the flags in pytest.ini, since I do rarely run benchmarks. The --ignore flag for pytest only helps against problem number 3.


Discussion / hints:

Fix patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 234bbea..dc7f717 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -30,3 +30,4 @@ Authors
 * Jonathan Simon Prates - https://github.com/jonathansp
 * Miroslav Šedivý - https://github.com/eumiro
 * Dimitris Rozakis - https://github.com/dimrozakis
+* Friedrich Delgado - https://github.com/TauPan
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index aeff133..2dafafc 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -2,6 +2,12 @@
 Changelog
 =========
 
+3.4.2 (2021-06-15)
+------------------
+
+* Don't save if ``--benchmark-disable`` is used.
+  Fixes `#205 <https://github.com/ionelmc/pytest-benchmark/issues/205`_.
+  Contributed by Friedrich Delgado in `#207 <https://github.com/ionelmc/pytest-benchmark/pull/207>`_.
 
 3.4.1 (2021-04-17)
 ------------------


Test patch:
diff --git a/src/pytest_benchmark/session.py b/src/pytest_benchmark/session.py
index 42b0f83..070e48d 100644
--- a/src/pytest_benchmark/session.py
+++ b/src/pytest_benchmark/session.py
@@ -135,8 +135,9 @@ def save_json(self, output_json):
     def handle_saving(self):
         save = self.save or self.autosave
         if save or self.json:
-            if not self.benchmarks and not self.disabled:
-                self.logger.warn("Not saving anything, no benchmarks have been run!")
+            if not self.benchmarks:
+                if not self.disabled:
+                    self.logger.warn("Not saving anything, no benchmarks have been run!")
                 return
             machine_info = self.get_machine_info()
             commit_info = self.config.hook.pytest_benchmark_generate_commit_info(config=self.config)